| Safe Haskell | None |
|---|
Network.HTTP.Toolkit
Contents
- data ToolkitError
- data InputStream
- makeInputStream :: IO ByteString -> IO InputStream
- inputStreamFromHandle :: Handle -> IO InputStream
- type RequestPath = ByteString
- data Request a = Request {
- requestMethod :: Method
- requestPath :: RequestPath
- requestHeaders :: [Header]
- requestBody :: a
- readRequestWithLimit :: Limit -> Bool -> InputStream -> IO (Request BodyReader)
- readRequest :: Bool -> InputStream -> IO (Request BodyReader)
- sendRequest :: (ByteString -> IO ()) -> Request BodyReader -> IO ()
- data Response a = Response {
- responseStatus :: Status
- responseHeaders :: [Header]
- responseBody :: a
- readResponseWithLimit :: Limit -> Bool -> Method -> InputStream -> IO (Response BodyReader)
- readResponse :: Bool -> Method -> InputStream -> IO (Response BodyReader)
- sendResponse :: (ByteString -> IO ()) -> Response BodyReader -> IO ()
- simpleResponse :: (ByteString -> IO ()) -> Status -> [Header] -> ByteString -> IO ()
- type BodyReader = IO ByteString
- sendBody :: (ByteString -> IO ()) -> BodyReader -> IO ()
- consumeBody :: BodyReader -> IO ByteString
- type Connection = InputStream
- makeConnection :: IO ByteString -> IO Connection
- connectionFromHandle :: Handle -> IO Connection
Exceptions
- All functions that consume input fail with
UnexpectedEndOfInputif the input ends before the function can completely successfully. - All cases where a function may fail with an exception other than
UnexpectedEndOfInputare 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 |
| ChunkTooLarge | The size of a body chunk exceeds
|
| 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.
inputStreamFromHandle :: Handle -> IO InputStreamSource
Create an InputStream from provided Handle.
Handling requests
type RequestPath = ByteStringSource
Constructors
| Request | |
Fields
| |
readRequestWithLimit :: Limit -> Bool -> InputStream -> IO (Request BodyReader)Source
Read request from provided InputStream.
The second argument is passed to makeChunkedReader.
Throws:
-
InvalidRequestLineif request-line is malformed. -
HeaderTooLargeif request-line and headers together exceed the specified sizeLimit -
InvalidHeaderif request-line is missing or a header is malformed
readRequest :: Bool -> InputStream -> IO (Request BodyReader)Source
Same as readRequestWithLimit with a Limit of defaultHeaderSizeLimit.
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
Constructors
| Response | |
Fields
| |
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:
-
InvalidStatusLineif status-line is malformed. -
HeaderTooLargeif status-line and headers together exceed the specified sizeLimit -
InvalidHeaderif status-line is missing or a header is malformed
readResponse :: Bool -> Method -> InputStream -> IO (Response BodyReader)Source
Same as readResponseWithLimit with a Limit of
defaultHeaderSizeLimit.
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
type Connection = InputStreamSource