httpp/hackney
This module contains the base code to interact with hackney in a low-level manner
Types
pub type Error {
Other(dynamic.Dynamic)
ConnectionClosed(partial_body: BitArray)
TimedOut
NoStatusOrHeaders
InvalidUtf8Response
NoClientRefReturned
UnexpectedServerMessage(HttppMessage)
MessageNotDecoded(dynamic.Dynamic)
}
Constructors
-
Other(dynamic.Dynamic)Hackney Error Type
-
ConnectionClosed(partial_body: BitArray)Error returned when the connection is unexpectedly closed
-
TimedOut -
NoStatusOrHeaders -
InvalidUtf8Responsecould not decode BitArray to string
-
NoClientRefReturnedwhen 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.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(#(String, String)),
client_ref: ClientRef,
)
BinaryResponse(
status: Int,
headers: List(#(String, String)),
body: BitArray,
)
EmptyResponse(status: Int, headers: List(#(String, String)))
AsyncResponse(client_ref: ClientRef)
}
Constructors
-
ClientRefResponse( status: Int, headers: List(#(String, String)), client_ref: ClientRef, )Received on response when neither
WithBodyorAsyncare used -
BinaryResponse( status: Int, headers: List(#(String, String)), body: BitArray, )Received when you use the
WithBody(True)Option -
EmptyResponse(status: Int, headers: List(#(String, String)))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(#(String, String)))
Binary(BitArray)
Redirect(String, List(#(String, String)))
SeeOther(String, List(#(String, String)))
DoneStreaming
NotDecoded(dynamic.Dynamic)
}
Constructors
-
Status(Int) -
Headers(List(#(String, String))) -
Binary(BitArray) -
Redirect(String, List(#(String, String))) -
SeeOther(String, List(#(String, String))) -
DoneStreaming -
NotDecoded(dynamic.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 -
AsyncReceive a
ClientRefback -
StreamTo(process.Pid)Receive the response as message, use the function
selecting_http_message -
FollowRedirect(Bool)Follow redirects, this enables the messages
RedirectandSeeOther -
MaxRedirect(Int)Max number of redirects
-
BasicAuth(BitArray, BitArray)Basic auth username/password
Values
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: process.Selector(a),
mapping transform: fn(ClientRef, HttppMessage) -> a,
) -> process.Selector(a)
if sending with async, put this in your selector to receive messages related to your request
pub fn send(
a: http.Method,
b: String,
c: List(#(String, String)),
d: bytes_tree.BytesTree,
e: List(Options),
) -> Result(HackneyResponse, Error)
Send hackney a request, this is basically the direct