http2-client- A native HTTP2 client library.

Safe HaskellNone




A toolbox with high-level functions to interact with an established HTTP2 conection.

These helpers make the assumption that you want to work in a multi-threaded environment and that you want to send and receiving whole HTTP requests at once (i.e., you do not care about streaming individual HTTP requests/responses but want to make many requests).


Sending and receiving HTTP body

upload Source #


:: ByteString

HTTP body.

-> Http2Client

The client.

-> OutgoingFlowControl

The outgoing flow control for this client. (We might remove this argument in the future because we can get it from the previous argument.

-> Http2Stream

The corresponding HTTP stream.

-> OutgoingFlowControl

The flow control for this stream.

-> IO () 

Uploads a whole HTTP body at a time.

This function should be called at most once per stream. This function closes the stream with HTTP2.setEndStream chunk at the end. If you want to post data (e.g., streamed chunks) your way to avoid loading a whole bytestring in RAM, please study the source code of this function first.

This function sends one chunk at a time respecting by preference: - server's flow control desires - server's chunking preference

Uploading an empty bytestring will send a single DATA frame with setEndStream and no payload.

waitStream :: Http2Stream -> IncomingFlowControl -> IO StreamResult Source #

Wait for a stream until completion.

This function is fine if you don't want to consume results in chunks. See fromStreamResult to collect the complicated StreamResult into a simpler StramResponse.

fromStreamResult :: StreamResult -> Either ErrorCode StreamResponse Source #

Converts a StreamResult to a StramResponse, stopping at the first error using the `Either HTTP2.ErrorCode` monad.

onPushPromise :: Http2Stream -> PushPromiseHandler -> IO () Source #

Sequentially wait for every push-promise with a handler.

This function runs forever and you should wrap it with withAsync.

type StreamResult = (Either ErrorCode HeaderList, [Either ErrorCode ByteString]) Source #

Result containing the unpacked headers and all frames received in on a stream. See StreamResponse and fromStreamResult to get a higher-level utility.

type StreamResponse = (HeaderList, ByteString) Source #

An HTTP2 response, once fully received, is made of headers and a payload.


ping Source #


:: Http2Client

client connection

-> Int

timeout in microseconds

-> ByteString

8-bytes message to uniquely identify the reply

-> IO PingReply 

Performs a ping and waits for a reply up to a given timeout (in microseconds).

data TimedOut Source #

Opaque type to express an action which timed out.