httpp/streaming
This module allows you to make an http request to a server and receive a streamed response back which is sent to a process managing it. You can also define a custom message type and send messages and state to this response handler.
Types
This defines the behaviour of the request handler
NOTE: if the on_error handler does not receive a response, the handler will be shut down regardless of if it returns an Ok() result
if the initial response does not arrive within the timeout, the on_error handler will receive the TimedOut error
pub type StreamingRequestHandler(state, message_type) {
StreamingRequestHandler(
initial_state: state,
req: request.Request(bytes_tree.BytesTree),
on_data: fn(Message, response.Response(Nil), state) -> Result(
state,
process.ExitReason,
),
on_message: fn(message_type, response.Response(Nil), state) -> Result(
state,
process.ExitReason,
),
on_error: fn(
hackney.Error,
option.Option(response.Response(Nil)),
state,
) -> Result(state, process.ExitReason),
initial_response_timeout: Int,
)
}
Constructors
-
StreamingRequestHandler( initial_state: state, req: request.Request(bytes_tree.BytesTree), on_data: fn(Message, response.Response(Nil), state) -> Result( state, process.ExitReason, ), on_message: fn(message_type, response.Response(Nil), state) -> Result( state, process.ExitReason, ), on_error: fn( hackney.Error, option.Option(response.Response(Nil)), state, ) -> Result(state, process.ExitReason), initial_response_timeout: Int, )
Values
pub fn start(
handler: StreamingRequestHandler(state, message_type),
) -> Result(
#(hackney.ClientRef, process.Subject(message_type)),
actor.StartError,
)
Starts a streaming request manager, based on the spec