Ankh.HTTP (ankh v0.17.0)

HTTP public interface

This module implements Ankh public APIs and provides protocol negotiation.

Link to this section Summary

Types

HTTP body

HTTP Header

HTTP Header name

HTTP Header value

HTTP Headers

Functions

Accepts an HTTP connection

Closes the underlying connection

Establishes an HTTP connection to a server

Reports a connection error

Sends a request to a server

Sends a response to a client request

Receives a transport message and returns responses

Receives data and returns responses

Link to this section Types

@type body() :: iodata()

HTTP body

@type complete() :: boolean()
@type header() :: {header_name(), header_value()}

HTTP Header

Link to this type

header_name()

@type header_name() :: String.t()

HTTP Header name

Link to this type

header_value()

@type header_value() :: String.t()

HTTP Header value

@type headers() :: [header()]

HTTP Headers

@type response() ::
  {:data, reference(), iodata(), complete()}
  | {:headers | :push_promise, reference(), headers(), complete()}
  | {:error, reference(), Ankh.HTTP.Error.reason(), complete()}

Link to this section Functions

Link to this function

accept(uri, socket, options \\ [])

@spec accept(URI.t(), Ankh.Transport.socket(), Ankh.Transport.options()) ::
  {:ok, Ankh.Protocol.t()} | {:error, any()}

Accepts an HTTP connection

After accepting the connection, stream will receive requests from the client and respond can be used to send replies.

Link to this function

close(protocol)

@spec close(Ankh.Protocol.t()) :: :ok | {:error, any()}

Closes the underlying connection

Link to this function

connect(uri, options \\ [])

@spec connect(URI.t(), Ankh.Transport.options()) ::
  {:ok, Ankh.Protocol.t()} | {:error, any()}

Establishes an HTTP connection to a server

After establishing the connection, request can be user to send request and stream can be used to receive responses from the server.

Link to this function

error(protocol)

@spec error(Ankh.Protocol.t()) :: :ok | {:error, any()}

Reports a connection error

Link to this function

header_name_valid?(name, strict)

@spec header_name_valid?(header_name(), boolean()) :: boolean()
Link to this function

request(protocol, request)

@spec request(Ankh.Protocol.t(), Ankh.HTTP.Request.t()) ::
  {:ok, Ankh.Protocol.t(), Ankh.Protocol.request_ref()} | {:error, any()}

Sends a request to a server

Needs a connection to be established via connect beforehand.

Link to this function

respond(protocol, reference, response)

@spec respond(Ankh.Protocol.t(), Ankh.Protocol.request_ref(), Ankh.HTTP.Response.t()) ::
  {:ok, Ankh.Protocol.t()} | {:error, any()}

Sends a response to a client request

Needs a connection to be accepted via accept beforehand.

Link to this function

stream(protocol, msg)

@spec stream(Ankh.Protocol.t(), Ankh.Transport.msg()) ::
  {:ok, Ankh.Protocol.t(), any()} | {:error, any()}

Receives a transport message and returns responses

Link to this function

stream_data(protocol, data)

@spec stream_data(Ankh.Protocol.t(), Ankh.Transport.data()) ::
  {:ok, Ankh.Protocol.t(), any()} | {:error, any()}

Receives data and returns responses

Link to this function

validate_trailers(list, strict)

@spec validate_trailers(headers(), boolean()) :: :ok | {:error, :protocol_error}