Safe Haskell | None |
---|
- type BodyReader = IO ByteString
- data BodyType
- bodyTypeFromHeaders :: [Header] -> Maybe BodyType
- makeBodyReader :: Bool -> BodyType -> InputStream -> IO BodyReader
- consumeBody :: BodyReader -> IO ByteString
- sendBody :: (ByteString -> IO ()) -> BodyReader -> IO ()
- fromByteString :: ByteString -> IO BodyReader
- maxChunkSize :: Int
- makeChunkedReader :: Bool -> InputStream -> IO BodyReader
- readChunkSize :: InputStream -> IO (Int, ByteString)
- makeLengthReader :: Int -> InputStream -> IO BodyReader
- makeUnlimitedReader :: InputStream -> 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
.
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 :: Bool -> BodyType -> InputStream -> IO BodyReaderSource
Create a BodyReader
from provided InputStream
and specified BodyType
.
The first argument is passed to makeChunkedReader
.
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 :: Bool -> InputStream -> IO BodyReaderSource
Create a reader for bodies with chunked transfer coding.
If the first argument is True
the body is returned raw, including chunk
sizes, chunk extensions and trailer.
If the first argument is False
only the decoded body is returned, chunk
extensions and trailer are striped.
The reader throws:
-
InvalidChunk
if the body is malformed. -
ChunkTooLarge
if the size of a chunk exceedsmaxChunkSize
.
readChunkSize :: InputStream -> 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 -> InputStream -> IO BodyReaderSource
Create a reader for bodies with a specified length.
makeUnlimitedReader :: InputStream -> IO BodyReaderSource
Create a reader for when the body length is determined by the server closing the connection.