Quiver.Conn.HTTP1 (quiver v0.2.0)

Copy Markdown View Source

HTTP/1.1 connection as a stateless data struct.

Wraps a TCP or SSL transport. Sequential request-response with keep-alive support.

Summary

Functions

Returns whether the connection may accept another request.

Receives the next chunk of response body data.

Receives response status and headers after a request has been sent via open_request/5.

Types

t()

@type t() :: %Quiver.Conn.HTTP1{
  buffer: binary(),
  closed: boolean(),
  host: String.t(),
  keep_alive: boolean(),
  parse_state: Quiver.Conn.HTTP1.Parse.parse_state(),
  port: :inet.port_number(),
  recv_timeout: timeout(),
  request_ref: reference() | nil,
  request_state: :idle | :in_flight,
  scheme: :http | :https,
  transport: Quiver.Transport.t(),
  transport_mod: module()
}

Functions

open?(http1)

Returns whether the connection may accept another request.

Does not probe the underlying transport -- a TCP reset that occurred since the last send/recv will not be detected here. Dead connections are discovered on the next request attempt.

recv_body_chunk(conn)

@spec recv_body_chunk(t()) ::
  {:ok, t(), binary()} | {:done, t()} | {:error, t(), term()}

Receives the next chunk of response body data.

Returns {:ok, conn, chunk} with binary data, {:done, conn} when the body is complete, or {:error, conn, reason} on failure.

recv_response_headers(conn)

@spec recv_response_headers(t()) ::
  {:ok, t(), non_neg_integer(), [{String.t(), String.t()}], [binary()]}
  | {:error, t(), term()}

Receives response status and headers after a request has been sent via open_request/5.

Returns any body data that arrived alongside the headers in initial_body_chunks. Call recv_body_chunk/1 to continue receiving the body.

stream_request(conn, method, path, headers, body_enum)

@spec stream_request(
  t(),
  Quiver.Conn.method(),
  String.t(),
  Quiver.Conn.headers(),
  Enumerable.t()
) :: {:ok, t(), Quiver.Response.t()} | {:error, t(), term()}