Skip to content

HttpIncomingMessage

Common model for incoming HTTP messages.

HttpIncomingMessage is used by server requests and client responses to expose headers, an optional remote address, and body accessors. This module provides decoders for JSON bodies, URL-encoded bodies, and headers, plus the shared body-size setting and inspection helper used by request and response implementations.

8 exports Added in v4.0.0 Source

Converting

inspect

Added in v4.0.0 Source

Builds an inspectable object for an incoming message, redacting headers and including a synchronously readable JSON or text body when available.

Signature

declare function inspect<E>(self: HttpIncomingMessage<E>, that: object): object;

Guards

Returns true when a value is an HttpIncomingMessage.

Signature

declare function isHttpIncomingMessage(u: unknown): u is HttpIncomingMessage<unknown>;

Models

HttpIncomingMessage interface

Added in v4.0.0 Source

Common model for incoming HTTP messages, with headers, remote address, and effectful body accessors.

Signature

interface HttpIncomingMessage<E = unknown> extends Inspectable {
  readonly "~effect/http/HttpIncomingMessage": "~effect/http/HttpIncomingMessage";
  readonly arrayBuffer: Effect<ArrayBuffer, E>;
  readonly headers: Headers;
  readonly json: Effect<Json, E>;
  readonly remoteAddress: Option<string>;
  readonly stream: Stream<Uint8Array<ArrayBufferLike>, E>;
  readonly text: Effect<string, E>;
  readonly urlParamsBody: Effect<UrlParams, E>;
}

References

MaxBodySize

Added in v4.0.0 Source

Context reference for the optional maximum size allowed when reading an incoming message body.

Signature

declare const MaxBodySize: Reference<Size | undefined>;

Schemas

Creates a decoder that reads an incoming message's JSON body and decodes it with the supplied schema.

Signature

declare function schemaBodyJson<S extends Constraint>(
  schema: S,
  options?: ParseOptions,
): <E>(self: HttpIncomingMessage<E>) => Effect<S["Type"], SchemaError | E, S["DecodingServices"]>;

Creates a decoder that reads an incoming message's URL-encoded body parameters and decodes them with the supplied schema.

Signature

declare function schemaBodyUrlParams<A, I extends Readonly<Record<string, string | readonly Array<string> | undefined>>, RD>(schema: ConstraintCodec<A, I, RD, unknown>, options?: ParseOptions): <E>(self: HttpIncomingMessage<E>) => Effect<A, SchemaError | E, RD>

Creates a decoder that validates and decodes an incoming message's headers with the supplied schema.

Signature

declare function schemaHeaders<A, I extends Readonly<Record<string, string | undefined>>, RD>(
  schema: ConstraintCodec<A, I, RD, unknown>,
  options?: ParseOptions,
): <E>(self: HttpIncomingMessage<E>) => Effect<A, SchemaError, RD>;

Type IDs

TypeId

Added in v4.0.0 Source

Type identifier for HttpIncomingMessage values.

Signature

declare const TypeId: "~effect/http/HttpIncomingMessage";