http-kit-0.2.1: A low-level HTTP library

Safe HaskellNone

Network.HTTP.Toolkit

Contents

Synopsis

Connection

data Connection Source

An abstract connection type that allows to read and unread input.

makeConnection :: IO ByteString -> IO ConnectionSource

Create a Connection from provided IO action.

Handling requests

data Request a Source

Instances

Functor Request 
Eq a => Eq (Request a) 
Show a => Show (Request a) 

readRequestWithLimit :: Limit -> Connection -> IO (Request BodyReader)Source

Read request from provided connection.

Throws:

sendRequest :: (ByteString -> IO ()) -> Request BodyReader -> IO ()Source

Send an HTTP request.

Note: The first argument to this function is used to send the data. For space efficiency it may be called multiple times.

Handling responses

data Response a Source

Constructors

Response 

Instances

Functor Response 
Eq a => Eq (Response a) 
Show a => Show (Response a) 

readResponseWithLimit :: Limit -> Method -> Connection -> IO (Response BodyReader)Source

Read response from provided connection.

The corresponding request Method has to be specified so that the body length can be determined (see RFC 2616, Section 4.4).

Throws:

sendResponse :: (ByteString -> IO ()) -> Response BodyReader -> IO ()Source

Send an HTTP response.

Note: The first argument to this function is used to send the data. For space efficiency it may be called multiple times.

simpleResponse :: (ByteString -> IO ()) -> Status -> [Header] -> ByteString -> IO ()Source

Send a simple HTTP response. The provided ByteString is used as the message body. A suitable Content-Length header is added to the specified list of headers.

Note: The first argument to this function is used to send the data. For space efficiency it may be called multiple times.

Handling message bodies

type BodyReader = IO ByteStringSource

A reader for HTTP bodies. It returns chunks of the body as long as there is more data to consume. When the body has been fully consumed, it returns empty.

sendBody :: (ByteString -> IO ()) -> BodyReader -> IO ()Source

Read input from provided BodyReader and wirte it to provided sink until all input has been consumed.

Note: The first argument to this function is used to send the data. For space efficiency it may be called multiple times.

consumeBody :: BodyReader -> IO ByteStringSource

Strictly consume all input from provided BodyReader.

Error type

data ToolkitError Source

Constructors

InvalidRequestLine ByteString

The request-line of the message is malformed.

InvalidStatusLine ByteString

The status-line of the message is malformed.

InvalidHeader

A header field is malformed.

HeaderTooLarge

The start-line of the message and all header fields together exceed the specified size Limit.

ChunkTooLarge

The size of a body chunk exceeds maxChunkSize.

InvalidChunk

A body chunk is malformed.