http2

Types

pub type Body {
  Bytes(BitArray)
  File(path: String, offset: Int, size: Int)
}

Constructors

  • Bytes(BitArray)
  • File(path: String, offset: Int, size: Int)
pub type BodyReadError {
  BodyTooLarge
  BodyReadTimeout
}

Constructors

  • BodyTooLarge
  • BodyReadTimeout
pub opaque type Builder
pub type Connection =
  @internal Connection
pub type ReadEvent {
  Chunk(data: BitArray, request: request.Request(Connection))
  Done(request: request.Request(Nil))
}

Constructors

Values

pub fn drain_timeout_ms(builder: Builder, value: Int) -> Builder

How long in milliseconds a draining connection waits for streams to finish after GOAWAY before force-closing. Default value is 4000.

pub fn file(
  path: String,
  offset offset: option.Option(Int),
  size size: option.Option(Int),
) -> Result(Body, @internal FileError)

Validates the path provided and builds a File response body from it. offset skips bytes from the start, size caps how many bytes are sent.

pub fn file_read_threshold(
  builder: Builder,
  value: Int,
) -> Builder

Files at or below this size in bytes are read into memory and sent through the same batched multi-frame path as any other response body, while larger files are streamed from disk using zero-copy sendfile. Must be non-negative. An invalid value is silently replaced with the default. Default value is 1MiB.

pub fn handshake_timeout_ms(
  builder: Builder,
  value: Int,
) -> Builder

How long in milliseconds a connection may sit in the preface and SETTINGS handshake before being dropped. Default value is 10000

pub fn header_table_size(builder: Builder, value: Int) -> Builder

SETTINGS_HEADER_TABLE_SIZE. Default value is 4096.

pub fn host(builder: Builder, host: String) -> Builder
pub fn initial_window_size(
  builder: Builder,
  value: Int,
) -> Builder

SETTINGS_INITIAL_WINDOW_SIZE. Must stay within 0-2147483647, out of range values are silently replaced with the default. Default value is 65535.

pub fn max_concurrent_streams(
  builder: Builder,
  value: option.Option(Int),
) -> Builder

SETTINGS_MAX_CONCURRENT_STREAMS. Use option.Some(n) to cap it, negative values and zero are silently replaced with default. By default it is unlimited

pub fn max_continuation_frames(
  builder: Builder,
  value: Int,
) -> Builder

Cap on CONTINUATION frames per HEADERS sequence. Default value is 100

pub fn max_frame_size(builder: Builder, value: Int) -> Builder

SETTINGS_MAX_FRAME_SIZE. Must stay within 16384-16777215, out of range values are silently replaced with the default. Default value is 16384.

pub fn max_header_block_bytes(
  builder: Builder,
  value: Int,
) -> Builder

Cap on cumulative HEADERS and CONTINUATION bytes per header block, checked before HPACK decode. Default value is 65536

pub fn max_header_list_size(
  builder: Builder,
  value: option.Option(Int),
) -> Builder

SETTINGS_MAX_HEADER_LIST_SIZE. Use option.Some(n) to cap it. By default it is unlimited.

pub fn new(
  handler: fn(request.Request(Connection)) -> response.Response(
    Body,
  ),
) -> Builder
pub fn port(builder: Builder, port: Int) -> Builder
pub fn rapid_reset(
  builder: Builder,
  window_ms window_ms: Int,
  threshold threshold: Int,
) -> Builder

Rapid Reset (CVE-2023-44487) mitigation that trips GOAWAY(ENHANCE_YOUR_CALM) once more than threshold client resets land within window_ms. Default values are 10000ms window and 100 threshold.

pub fn read_body(
  req: request.Request(Connection),
  bytes_limit: Int,
) -> Result(request.Request(BitArray), BodyReadError)
pub fn read_body_chunk(
  req: request.Request(Connection),
  max_chunk_bytes: Int,
) -> Result(ReadEvent, BodyReadError)

Pulls up to max_chunk_bytes of body per call instead of buffering the whole body. The returned request carries the updated Connection, feed it back into the next call. Ends with Done that includes request with trailers merged in.

pub fn recv_window_water_marks(
  builder: Builder,
  low low: Int,
  high high: Int,
) -> Builder

Recv window low and high water marks. Once a stream’s or the connection’s recv window drops to or below low, it’s topped back up to high in one shot instead of trickling small WINDOW_UPDATE deltas. The bigger gap between the two means fewer WINDOW_UPDATE round trips for large bodies. low must be positive and below high and high must not exceed 2147483647. An invalid pair is silently replaced with the defaults. Default values are 256KiB low and 2MiB high.

Search Document