httpp/hackney
This module contains the base code to interact with hackney in a low-level manner
Types
pub type Error {
Other(Dynamic)
ConnectionClosed(partial_body: BitArray)
TimedOut
NoStatusOrHeaders
InvalidUtf8Response
NoClientRefReturned
UnexpectedServerMessage(HttppMessage)
MessageNotDecoded(Dynamic)
}
Constructors
-
Other(Dynamic)
Hackney Error Type
-
ConnectionClosed(partial_body: BitArray)
Error returned when the connection is unexpectedly closed
-
TimedOut
-
NoStatusOrHeaders
-
InvalidUtf8Response
could not decode BitArray to string
-
NoClientRefReturned
when expecting a client ref, we did not get one back
-
UnexpectedServerMessage(HttppMessage)
when the client has already received a message and doesn’t expect the message
-
MessageNotDecoded(Dynamic)
when the client receives a message that it can’t decode
Response of the hackney http client
pub type HackneyResponse {
ClientRefResponse(
status: Int,
headers: List(Header),
client_ref: ClientRef,
)
BinaryResponse(
status: Int,
headers: List(Header),
body: BitArray,
)
EmptyResponse(status: Int, headers: List(Header))
AsyncResponse(client_ref: ClientRef)
}
Constructors
-
ClientRefResponse( status: Int, headers: List(Header), client_ref: ClientRef, )
Received on response when neither
WithBody
orAsync
are used -
BinaryResponse( status: Int, headers: List(Header), body: BitArray, )
Received when you use the
WithBody(True)
Option -
EmptyResponse(status: Int, headers: List(Header))
This is received on a HEAD request when response succeeded
-
AsyncResponse(client_ref: ClientRef)
This is received when used with the option Async You can use the passed in client ref to disambiguate messages received
pub type HttppMessage {
Status(Int)
Headers(List(Header))
Binary(BitArray)
Redirect(String, List(Header))
SeeOther(String, List(Header))
DoneStreaming
NotDecoded(Dynamic)
}
Constructors
-
Status(Int)
-
Headers(List(Header))
-
Binary(BitArray)
-
Redirect(String, List(Header))
-
SeeOther(String, List(Header))
-
DoneStreaming
-
NotDecoded(Dynamic)
In case we couldn’t decode the message, you’ll get the dynamic version
pub type Options {
WithBody(Bool)
MaxBody(Int)
Async
StreamTo(process.Pid)
FollowRedirect(Bool)
MaxRedirect(Int)
BasicAuth(BitArray, BitArray)
}
Constructors
-
WithBody(Bool)
Receive a binary response
-
MaxBody(Int)
If using
WithBody(True)
, set maximum body size -
Async
Receive a
ClientRef
back -
StreamTo(process.Pid)
Receive the response as message, use the function
selecting_http_message
-
FollowRedirect(Bool)
Follow redirects, this enables the messages
Redirect
andSeeOther
-
MaxRedirect(Int)
Max number of redirects
-
BasicAuth(BitArray, BitArray)
Basic auth username/password
Functions
pub fn body(ref client_ref: ClientRef) -> Result(BitArray, Error)
retrieve the full body from a client_ref
pub fn body_string(
ref client_ref: ClientRef,
) -> Result(String, Error)
retrieve the full body from a client ref as a string
pub fn selecting_http_message(
selector: Selector(a),
mapping transform: fn(ClientRef, HttppMessage) -> a,
) -> Selector(a)
if sending with async, put this in your selector to receive messages related to your request