Skip to content

gluegun/client

High-level HTTP helpers for existing Gun connections.

These helpers collect a full HTTP/1.1 or HTTP/2 response — status, headers, body, trailers, and any informational 1xx responses — into a response.Response. The body is held fully in memory; use the lower-level gluegun/request and gluegun/message APIs for streaming or very large responses.

Protocol messages for server push, upgrades, and WebSockets are rejected with InvalidMessage. Use the lower-level gluegun/message API for those flows.

If collection fails, these helpers attempt to cancel the failed stream and drain its queued messages, then return the original error. They keep other streams and the connection open. Cancellation is asynchronous: messages in transit can arrive after the drain. For strict mailbox isolation, use the low-level API in a separate receiving process.

A buildable HTTP request: method, path, headers, body, options, and timeout.

pub type Request

Append request headers.

pub fn add_headers(
Request,
headers: List(#(String, String))
) -> Request

Send DELETE on an open connection and collect the full response.

pub fn delete(
internal.Connection,
String,
List(#(String, String)),
connection.Timeout
) -> Result(response.Response, error.GluegunError)

Send GET on an open connection and collect the full response.

pub fn get(
internal.Connection,
String,
List(#(String, String)),
connection.Timeout
) -> Result(response.Response, error.GluegunError)

Send HEAD on an open connection and collect the full response.

pub fn head(
internal.Connection,
String,
List(#(String, String)),
connection.Timeout
) -> Result(response.Response, error.GluegunError)

Start a new Request builder with the given method and path.

pub fn new(
request.Method,
String
) -> Request

Send PATCH on an open connection and collect the full response.

pub fn patch(
internal.Connection,
String,
List(#(String, String)),
BitArray,
connection.Timeout
) -> Result(response.Response, error.GluegunError)

Send POST on an open connection and collect the full response.

pub fn post(
internal.Connection,
String,
List(#(String, String)),
BitArray,
connection.Timeout
) -> Result(response.Response, error.GluegunError)

Send PUT on an open connection and collect the full response.

pub fn put(
internal.Connection,
String,
List(#(String, String)),
BitArray,
connection.Timeout
) -> Result(response.Response, error.GluegunError)

Send OPTIONS on an open connection and collect the full response.

pub fn request_options(
internal.Connection,
String,
List(#(String, String)),
connection.Timeout
) -> Result(response.Response, error.GluegunError)

Send a built Request on an open connection and collect the response.

pub fn send(
Request,
connection: internal.Connection
) -> Result(response.Response, error.GluegunError)

Replace the request body.

pub fn with_body(
Request,
body: BitArray
) -> Request

Append a single request header.

pub fn with_header(
Request,
name: String,
value: String
) -> Request

Replace request headers.

pub fn with_headers(
Request,
headers: List(#(String, String))
) -> Request

Replace low-level request options.

pub fn with_options(
Request,
options: request.RequestOptions
) -> Request

Replace the request timeout.

pub fn with_timeout(
Request,
timeout: connection.Timeout
) -> Request