GitHub

HttpPlatformService

API reference for HttpPlatformService.

The HttpPlatform service: make builds it, and HttpPlatformService(platform, compression, file_response, file_web_response) makes one of functions (a test double, say).

Attributes

AttributeTypeDescription
platformPlatformName = platform
compressionCompression = compression

Functions

__init__

__init__(platform, compression, file_response, file_web_response) -> None
ParameterTypeDescription
platformPlatformName
compressionCompression
file_responseCallable[..., Effect[HttpServerResponse, PlatformError]]
file_web_responseCallable[..., Effect[HttpServerResponse]]
def __init__(
    self,
    platform: PlatformName,
    compression: Compression,
    file_response: Callable[..., Effect[HttpServerResponse, PlatformError]],
    file_web_response: Callable[..., Effect[HttpServerResponse]],
) -> None:
    self.platform = platform
    self.compression = compression
    self._file_response = file_response
    self._file_web_response = file_web_response

file_response

file_response(path, **options) -> Effect[HttpServerResponse, PlatformError]

A response streaming the file at path, with an etag and a last-modified header from its stat. offset and bytes_to_read pick a range (clamped to the file); status, status_text, headers and content_type go on the response. Fails with a PlatformError when the file cannot be stat'ed, or offset or bytes_to_read is invalid.

ParameterTypeDescription
pathstr
optionsUnpack[FileOptions] = {}

Returns Effect[HttpServerResponse, PlatformError]

def file_response(
    self, path: str, **options: Unpack[FileOptions]
) -> Effect[HttpServerResponse, PlatformError]:
    """A response streaming the file at ``path``, with an ``etag``
    and a ``last-modified`` header from its ``stat``. ``offset`` and
    ``bytes_to_read`` pick a range (clamped to the file); ``status``,
    ``status_text``, ``headers`` and ``content_type`` go on the
    response. Fails with a ``PlatformError`` when the file cannot be
    stat'ed, or ``offset`` or ``bytes_to_read`` is invalid."""
    return self._file_response(path, **options)

file_web_response

file_web_response(file, **options) -> Effect[HttpServerResponse]

A response streaming the file-like file, with an etag and a last-modified header; offset, bytes_to_read and chunk_size pick the range and its chunks, and the other options go on the response. Never fails.

ParameterTypeDescription
fileFileLike
optionsUnpack[FileWebOptions] = {}

Returns Effect[HttpServerResponse]

def file_web_response(
    self, file: FileLike, **options: Unpack[FileWebOptions]
) -> Effect[HttpServerResponse]:
    """A response streaming the file-like ``file``, with an ``etag``
    and a ``last-modified`` header; ``offset``, ``bytes_to_read`` and
    ``chunk_size`` pick the range and its chunks, and the other options
    go on the response. Never fails."""
    return self._file_web_response(file, **options)