Safe Haskell | None |
---|
Network.HTTP.Toolkit
- data Connection
- makeConnection :: IO ByteString -> IO Connection
- connectionFromHandle :: Handle -> IO Connection
- type RequestPath = ByteString
- 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 ()
- simpleResponse :: (ByteString -> IO ()) -> Status -> [Header] -> ByteString -> 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
type RequestPath = ByteStringSource
Constructors
Request | |
Fields
|
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.
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 -> 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.
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
.
Error type
data ToolkitError Source
Constructors
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. |