HttpPlatform
Platform-specific support for serving files as HTTP server responses.
HttpPlatform is the boundary between the portable HTTP response model and the runtime that knows how to stream bytes from the host platform. Server code uses this service when it needs to return local files, static assets, downloads, byte ranges, or Web File-like values without constructing the response body by hand.
Compression
Compression interface
Signature
interface Compression {
readonly algorithms: ReadonlySet<CompressionAlgorithm>;
readonly compressResponse: (
response: HttpServerResponse,
algorithm: CompressionAlgorithm,
options?: CompressionOptions,
) => Effect<HttpServerResponse>;
}CompressionAlgorithm type
Content codings that HTTP response compression can apply.
Signature
type CompressionAlgorithm = "gzip" | "deflate" | "br" | "zstd";CompressionOptions interface
Options passed to a platform when compressing a response body.
Details
The level scale depends on the algorithm. Platforms without a level knob, such as the Web CompressionStream implementation, ignore it.
Signature
interface CompressionOptions {
readonly level?: number;
}compressionTransformWeb
Creates a compression body transform backed by the Web CompressionStream API, for use with makeCompressionWeb.
Details
The format string is passed through to the runtime, so runtime-specific formats such as Bun's "brotli" and "zstd" are usable. CompressionStream has no compression level knob, so CompressionOptions.level does not apply.
Signature
declare const compressionTransformWeb: (
format: string,
) => (stream: ReadableStream<Uint8Array>) => ReadableStream<Uint8Array>;makeCompressionWeb
Creates a Compression implementation from Web ReadableStream transforms.
Details
All supported bodies are transformed as streams. The Content-Length header is dropped in every case.
Signature
declare const makeCompressionWeb: (options: {
readonly algorithms: Iterable<CompressionAlgorithm>;
readonly transform: (
algorithm: CompressionAlgorithm,
options?: CompressionOptions,
) => (stream: ReadableStream<Uint8Array>) => ReadableStream<Uint8Array>;
}) => Compression;Constructors
Creates an HttpPlatform service from platform-specific file response constructors, using FileSystem and Etag.Generator.
Signature
declare const make: (impl: {
readonly compression: Compression;
readonly fileResponse: (
path: string,
status: number,
statusText: string | undefined,
headers: Headers.Headers,
start: number,
end: number | undefined,
contentLength: number,
) => Response.HttpServerResponse;
readonly fileWebResponse: (
file: Body.HttpBody.FileLike,
status: number,
statusText: string | undefined,
headers: Headers.Headers,
options?: {
readonly bytesToRead?: FileSystem.SizeInput;
readonly chunkSize?: FileSystem.SizeInput;
readonly offset?: FileSystem.SizeInput;
},
) => Response.HttpServerResponse;
readonly platform: "deno" | "node" | "bun" | "web";
}) => Effect.Effect<HttpPlatform["Service"], never, Etag.Generator | FileSystem.FileSystem>;Layers
Provides the default HttpPlatform implementation for serving file paths and File-like values as streamed HTTP responses.
Details
The layer uses the FileSystem and weak ETag services to add file metadata headers such as etag and last-modified.
Signature
declare const layer: Layer<HttpPlatform, never, FileSystem>;Services
HttpPlatform
Service for platform-specific HTTP response helpers, including file-backed server responses.
Signature
declare class HttpPlatform extends Shape<
"effect/http/HttpPlatform",
{
readonly compression: Compression;
readonly fileResponse: (
path: string,
options?: WithContent & {
readonly bytesToRead?: SizeInput;
readonly chunkSize?: SizeInput;
readonly offset?: SizeInput;
},
) => Effect<HttpServerResponse, PlatformError>;
readonly fileWebResponse: (
file: FileLike,
options?: WithContent & {
readonly bytesToRead?: SizeInput;
readonly chunkSize?: SizeInput;
readonly offset?: SizeInput;
},
) => Effect<HttpServerResponse>;
readonly platform: "deno" | "node" | "bun" | "web";
},
this
> {
constructor(_: never);
}
Platform primitive for HTTP response compression.
Details
algorithmsadvertises what the platform can encode; content negotiation happens in the sharedHttpMiddleware.compressionmiddleware.compressResponseis only called when compression is definitely happening โ all skip logic runs in the shared middleware first. The platform owns the body transform and removesContent-Lengthwhen the compressed size is not known in advance. Themakewrapper owns theContent-EncodingandVaryheaders.