libduvet/http/transport
Types
Why an exchange didn’t finish.
pub type ExchangeError {
Timeout
Network(String)
}
Constructors
-
TimeoutNo progress for the transport’s timeout.
-
Network(String)The connection failed, was closed, or something else went wrong. The string is the lower-level reason, for logs.
One HTTP exchange, as the transport sees it: everything already encoded, with no interpretation of the answer.
pub type Request {
Request(
method: String,
url: String,
headers: List(#(String, String)),
body: List(BitArray),
)
}
Constructors
-
Request( method: String, url: String, headers: List(#(String, String)), body: List(BitArray), )Arguments
- body
-
The body, in pieces of at most 64 KiB: [] for none.
pub type Response {
Response(
status: Int,
headers: List(#(String, String)),
body: BitArray,
)
}
Constructors
-
Response( status: Int, headers: List(#(String, String)), body: BitArray, )
Performs one exchange. Reports the bytes of the request body sent and of the answer received so far through the callback, which is how the caller’s idle timeout follows progress.
The real transport blocks: the caller runs it in a process it can kill to abort the exchange, which closes the connection.
pub type Transport =
fn(Request, fn(Int) -> Nil, fn() -> Nil) -> Result(
Response,
ExchangeError,
)
Values
pub fn hackney(
timeout_ms: Int,
) -> fn(Request, fn(Int) -> Nil, fn() -> Nil) -> Result(
Response,
ExchangeError,
)
The transport the library ships: hackney, through duvet_network_ffi.
[timeout_ms] bounds each wait for progress at the socket level as well as the caller’s own timer, so a stuck exchange can’t outlive it if the caller is killed at an awkward moment.
pub fn header(
response: Response,
name: String,
) -> Result(String, Nil)
A header’s value, case-insensitively, as HTTP has them.
pub fn response_text(response: Response) -> String
The bytes of the request body sent so far. Any progress at all, response bytes included: it resets the idle timeout without being reported as sent bytes. The body of [response] as a string, when it’s valid UTF-8.