Skip to content
Welcome to the Gluegun documentation!

gluegun/request

Low-level HTTP request and stream operations.

Use this module when you need Gun stream references, chunked request bodies, flow-control updates, cancellation, or direct access to asynchronous Gun messages. For simple full-body responses, prefer gluegun/client.

HTTP request method constructors.

Use canonical constructors such as Get, Post, and Put, or Custom for extension methods.

  • Get()
  • Head()
  • Post()
  • Put()
  • Patch()
  • Delete()
  • Options()
  • Trace()
  • Connect()
  • Custom(String)

Request options passed through the low-level request API.

HTTP header represented as #(name, value).

pub type Header = Unknown

Cancel a request stream.

pub fn cancel(gluegun/internal.Connection, gluegun/internal.Stream) -> Result(Nil, gluegun/error.GluegunError)

Stream request body data for a request.

pub fn data(gluegun/internal.Connection, gluegun/internal.Stream, gluegun/fin.Fin, BitArray) -> Result(Nil, gluegun/error.GluegunError)

Flush Gun messages for a connection.

pub fn flush(gluegun/internal.Connection) -> Result(Nil, gluegun/error.GluegunError)

Start a low-level HTTP request whose body will be streamed later.

The caller must send request body chunks with data(..., fin.NoFin, ...) and complete the request with data(..., fin.Fin, ...). Gun response messages go to the calling process by default unless Gun request options redirect replies.

pub fn headers(gluegun/internal.Connection, gluegun/request.Method, String, List(#(String, String)), gluegun/request.RequestOptions) -> Result(gluegun/internal.Stream, gluegun/error.GluegunError)

Convert a method constructor to its HTTP method string.

pub fn method_to_string(gluegun/request.Method) -> String

Lowercase header names for the Erlang Gun FFI boundary without changing values.

pub fn normalize_headers(List(#(String, String))) -> List(#(String, String))

Construct default request options.

pub fn options() -> gluegun/request.RequestOptions

Send a low-level HTTP request on an open Gun connection.

This returns a stream reference. Use gluegun/client helpers to collect a regular HTTP response into a Response.

pub fn request(gluegun/internal.Connection, gluegun/request.Method, String, List(#(String, String)), BitArray, gluegun/request.RequestOptions) -> Result(gluegun/internal.Stream, gluegun/error.GluegunError)

Replace option-level headers.

pub fn set_headers(gluegun/request.RequestOptions, headers: List(#(String, String))) -> gluegun/request.RequestOptions

Update HTTP/1.1 or HTTP/2 stream flow control by the given increment.

The increment must be positive. Gun rejects non-positive flow-control increments, so this function validates the value before crossing the FFI boundary and returns InvalidOptions for zero or negative increments.

pub fn update_flow(gluegun/internal.Connection, gluegun/internal.Stream, Int) -> Result(Nil, gluegun/error.GluegunError)

Add option-level headers that are appended to per-call headers.

pub fn with_headers(gluegun/request.RequestOptions, headers: List(#(String, String))) -> gluegun/request.RequestOptions