gleam/httpd

Types

pub opaque type Configuration

Values

pub fn after_start(
  config: Configuration,
  callback: fn() -> Nil,
) -> Configuration

Sets a function to be called after the server successfully starts.

If not set then the default behaviour is to emit an INFO level log with the text “httpd listening on scheme://host:port”.

pub fn bind(
  config: Configuration,
  interface: String,
) -> Configuration

A hostname or IP address to bind to.

If this contains a : then IPv6 will be used. If it contains a . then IPv4 will be used. If it contains neither than the configured IP family will not be changed, with the default being IPv6. Many operating systems are “dual-stack” so will also accept IPv4 requests when IPv6 is selected.

Defaults to localhost.

pub fn chunked_transfer_encoding(
  config: Configuration,
  chunked_transfer_encoding: Bool,
) -> Configuration

Instructs the server whether to use chunked transfer-encoding when sending a response to an HTTP/1.1 client.

The default is true.

pub fn ipv4(config: Configuration) -> Configuration

Use IPv4. If this function and the bind function are not called then the default is IPv6.

Many operating systems are “dual-stack” so will also accept IPv4 requests when IPv6 is selected.

pub fn ipv6(config: Configuration) -> Configuration

Use IPv6. This is the default behaviour.

Many operating systems are “dual-stack” so will also accept IPv4 requests when IPv6 is selected.

pub fn keep_alive(
  config: Configuration,
  keep_alive: Bool,
) -> Configuration

Instructs the server whether to use persistent connections when the client claims to be HTTP/1.1 compliant.

The default is true.

pub fn keep_alive_timeout(
  config: Configuration,
  seconds: Int,
) -> Configuration

The number of seconds the server waits for a subsequent request from a HTTP/1.1 client before closing the connection.

Must be greater than zero. The default is 150.

If keep_alive is set to false then this option does nothing.

pub fn max_body_size(
  config: Configuration,
  bytes limit: Int,
) -> Configuration

Limits the size of the message body of an HTTP request.

The default is 2 MB.

pub fn max_clients(
  config: Configuration,
  max_clients: Int,
) -> Configuration

Limits the number of simultaneous requests that can be supported.

The default is 150.

pub fn max_header_size(
  config: Configuration,
  bytes limit: Int,
) -> Configuration

Limits the size of the message header of an HTTP request.

The default is 10 KB.

pub fn max_uri_size(
  config: Configuration,
  bytes limit: Int,
) -> Configuration

Limits the size of the HTTP request URI.

The default is 8 KB.

pub fn minimum_bytes_per_second(
  config: Configuration,
  limit: Int,
) -> Configuration

Sets a minimum of bytes per second value for connections.

If the value is unreached, the socket closes for that connection.

pub fn new(
  handler: fn(request.Request(BitArray)) -> response.Response(
    bytes_tree.BytesTree,
  ),
) -> Configuration

Create a new httpd configuration. See the functions in this module for the configuration options and their default values.

pub fn port(config: Configuration, port: Int) -> Configuration

The port to listen on. The default is 3000.

pub fn start(
  config: Configuration,
) -> Result(actor.Started(Nil), actor.StartError)

Start the httpd server.

You should add this to your supervision tree.

Search Document