Safe Haskell | None |
---|
- data Connection
- makeConnection :: IO ByteString -> IO Connection
- connectionFromHandle :: Handle -> IO Connection
- data Request a = Request {
- requestMethod :: Method
- requestPath :: RequestPath
- requestHeaders :: [Header]
- requestBody :: a
- readRequestWithLimit :: Limit -> Connection -> IO (Request BodyReader)
- readRequest :: Connection -> IO (Request BodyReader)
- sendRequest :: (ByteString -> IO ()) -> Request BodyReader -> IO ()
- data Response a = Response {
- responseStatus :: Status
- responseHeaders :: [Header]
- responseBody :: a
- readResponseWithLimit :: Limit -> Method -> Connection -> IO (Response BodyReader)
- readResponse :: Method -> Connection -> IO (Response BodyReader)
- sendResponse :: (ByteString -> IO ()) -> Response BodyReader -> IO ()
- type BodyReader = IO ByteString
- sendBody :: (ByteString -> IO ()) -> BodyReader -> IO ()
- consumeBody :: BodyReader -> IO ByteString
- data ToolkitError
Connection
data Connection Source
An abstract connection type that allows to read and unread input.
makeConnection :: IO ByteString -> IO ConnectionSource
Create a Connection
from provided IO
action.
connectionFromHandle :: Handle -> IO ConnectionSource
Create a Connection
from provided Handle
.
Handling requests
Request | |
|
readRequestWithLimit :: Limit -> Connection -> IO (Request BodyReader)Source
Read request from provided connection.
Throws:
-
InvalidRequestLine
if request-line is malformed. -
HeaderTooLarge
if request-line and headers together exceed the specified sizeLimit
-
InvalidHeader
if request-line is missing or a header is malformed
readRequest :: Connection -> IO (Request BodyReader)Source
Same as readRequestWithLimit
with a Limit
of defaultHeaderSizeLimit
.
sendRequest :: (ByteString -> IO ()) -> Request BodyReader -> IO ()Source
Send an HTTP request.
Handling responses
Response | |
|
readResponseWithLimit :: Limit -> Method -> Connection -> IO (Response BodyReader)Source
Read response from provided connection.
The corresponding request Method
has to be specified so that the body length can be determined (see
RFC 2616, Section 4.4).
Throws:
-
InvalidStatusLine
if status-line is malformed. -
HeaderTooLarge
if status-line and headers together exceed the specified sizeLimit
-
InvalidHeader
if status-line is missing or a header is malformed
readResponse :: Method -> Connection -> IO (Response BodyReader)Source
Same as readResponseWithLimit
with a Limit
of
defaultHeaderSizeLimit
.
sendResponse :: (ByteString -> IO ()) -> Response BodyReader -> IO ()Source
Send an HTTP response.
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.
consumeBody :: BodyReader -> IO ByteStringSource
Strictly consume all input from provided BodyReader
.
Error type
data ToolkitError Source
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. |