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

Safe HaskellNone

Network.HTTP.Toolkit.Body

Contents

Synopsis

Documentation

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.

data BodyType Source

Constructors

None

The message has no body.

Chunked

The message has a body. Chunked transfer coding is used to determine the message length (see RFC 2616, Section 3.6.1).

Length Int

The message has a body with a specified length.

Unlimited

The message has a body. The body length is determined by the server closing the connection. This is only a valid approach for response bodies. It can not be used for request bodies.

Instances

bodyTypeFromHeaders :: [Header] -> Maybe BodyTypeSource

Determine the message BodyType from a given list of message headers (as of RFC 2616, Section 4.4).

This is only a partial breakdown. Additional rules apply for request and response bodies respectively (see determineRequestBodyType and determineResponseBodyType).

makeBodyReader :: Connection -> BodyType -> IO BodyReaderSource

Create a BodyReader from provided Connection and specified BodyType.

consumeBody :: BodyReader -> IO ByteStringSource

Strictly consume all input from provided BodyReader.

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.

Handling of specific body types

maxChunkSize :: IntSource

The maximum size of a chunk in bytes when chunked transfer coding is used. The value depends on the bitSize of Int:

  • 2^28 on 32-bit systems
  • 2^60 on 64-bit systems

makeChunkedReader :: Connection -> IO BodyReaderSource

Create a reader for bodies with chunked transfer coding.

The reader throws:

readChunkSize :: Connection -> IO (Int, ByteString)Source

Read size of next body chunk for when chunked transfer coding is used.

Throws:

makeLengthReader :: Int -> Connection -> IO BodyReaderSource

Create a reader for bodies with a specified length.

makeUnlimitedReader :: Connection -> IO BodyReaderSource

Create a reader for when the body length is determined by the server closing the connection.