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

Safe HaskellNone

Network.HTTP.Toolkit

Contents

Synopsis

Exceptions

  • All functions that consume input fail with UnexpectedEndOfInput if the input ends before the function can completely successfully.
  • All cases where a function may fail with an exception other than UnexpectedEndOfInput are documented thoroughly on a per function level.

data ToolkitError Source

Constructors

UnexpectedEndOfInput

The input ended unpexpectedly while reading a message.

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.

Input handling

data InputStream Source

An abstraction for input streams that allows to read and unread input.

makeInputStream :: IO ByteString -> IO InputStreamSource

Create an InputStream from provided IO action.

Handling requests

readRequestWithLimit :: Limit -> Bool -> InputStream -> IO (Request BodyReader)Source

Read request from provided InputStream.

The second argument is passed to makeChunkedReader.

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

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

Read response from provided InputStream.

The second argument is passed to makeChunkedReader.

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.

Deprecated types and functions