HTTP.FetchOptions (http_fetch v0.11.0)

View Source

Options processing for HTTP.fetch/2 requests.

HTTP.fetch/2 accepts a flat init keyword list or map, mirroring the browser fetch(input, init) shape. Supported fetch-style options are:

  • method - HTTP method, defaulting to GET
  • headers - request headers as a list, map, or HTTP.Headers
  • body - request body
  • duplex - request streaming mode; :half or "half" for streaming bodies
  • signal - HTTP.AbortController PID
  • redirect - :follow, :manual, or :error; defaults to :follow

The socket transport also accepts Elixir-specific extensions:

  • content_type - convenience Content-Type value for request bodies
  • timeout - request timeout in milliseconds
  • connect_timeout - connection timeout in milliseconds
  • http_version - protocol selection, one of :http1, :http2, :http3, :h2c, or :auto; defaults to :http1
  • ssl - TLS options passed to :ssl
  • socket_opts - socket options passed to the underlying transport
  • unix_socket - Unix Domain Socket path

Summary

Functions

Extracts body from options.

Extracts content type from options.

Extracts the request body streaming mode from options.

Extracts headers from options.

Extracts the HTTP method from options.

Creates a new FetchOptions struct from a flat map, keyword list, or existing FetchOptions struct.

Converts fetch init options to the internal socket transport option list.

Types

http_version()

@type http_version() :: :http1 | :http2 | :http3 | :h2c | :auto

redirect()

@type redirect() :: :follow | :manual | :error

t()

@type t() :: %HTTP.FetchOptions{
  body: any(),
  connect_timeout: integer() | nil,
  content_type: String.t() | nil,
  duplex: :half | nil,
  headers: HTTP.Headers.t(),
  http_version: http_version(),
  method: atom(),
  redirect: redirect(),
  signal: any() | nil,
  socket_opts: list() | nil,
  ssl: list() | nil,
  timeout: integer() | nil,
  unix_socket: String.t() | nil
}

Functions

get_body(fetch_options)

@spec get_body(t()) :: any()

Extracts body from options.

get_content_type(fetch_options)

@spec get_content_type(t()) :: String.t() | nil

Extracts content type from options.

get_duplex(fetch_options)

@spec get_duplex(t()) :: :half | nil

Extracts the request body streaming mode from options.

get_headers(fetch_options)

@spec get_headers(t()) :: HTTP.Headers.t()

Extracts headers from options.

get_method(fetch_options)

@spec get_method(t()) :: atom()

Extracts the HTTP method from options.

new(options)

@spec new(map() | keyword() | t()) :: t()

Creates a new FetchOptions struct from a flat map, keyword list, or existing FetchOptions struct.

to_transport_options(options)

@spec to_transport_options(t()) :: keyword()

Converts fetch init options to the internal socket transport option list.