Safe Haskell | None |
---|
Network.HTTP.Toolkit.Body
Contents
- type BodyReader = IO ByteString
- data BodyType
- bodyTypeFromHeaders :: [Header] -> Maybe BodyType
- makeBodyReader :: Connection -> BodyType -> IO BodyReader
- consumeBody :: BodyReader -> IO ByteString
- sendBody :: (ByteString -> IO ()) -> BodyReader -> IO ()
- fromByteString :: ByteString -> IO BodyReader
- maxChunkSize :: Int
- makeChunkedReader :: Connection -> IO BodyReader
- readChunkSize :: Connection -> IO (Int, ByteString)
- makeLengthReader :: Int -> Connection -> IO BodyReader
- makeUnlimitedReader :: Connection -> IO BodyReader
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
.
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. |
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.
fromByteString :: ByteString -> IO BodyReaderSource
Create a BodyReader
from provided ByteString
.
Handling of specific body types
makeChunkedReader :: Connection -> IO BodyReaderSource
Create a reader for bodies with chunked transfer coding.
The reader throws:
-
InvalidChunk
if the body is malformed. -
ChunkTooLarge
if the size of a chunk exceedsmaxChunkSize
.
readChunkSize :: Connection -> IO (Int, ByteString)Source
Read size of next body chunk for when chunked transfer coding is used.
Throws:
-
ChunkTooLarge
if chunk size exceedsmaxChunkSize
.
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.