-- Hoogle documentation, generated by Haddock
-- See Hoogle, http://www.haskell.org/hoogle/
-- | A low-level HTTP library
--
-- A low-level HTTP library that can be used to build more sophisticated
-- applications on top of it.
--
-- The design goals are:
--
--
-- - secure To mitigate denial-of-service attacks, everything is
-- bounded.
-- - efficient Message bodies are read in chunks, so that they
-- can be processed in constant space.
-- - universal No framework for streaming IO is used.
-- This allows you to build on top of it, using the libraries that fit
-- your purpose.
--
@package http-kit
@version 0.2.1
module Network.HTTP.Toolkit.Error
data ToolkitError
-- | The request-line of the message is malformed.
InvalidRequestLine :: ByteString -> ToolkitError
-- | The status-line of the message is malformed.
InvalidStatusLine :: ByteString -> ToolkitError
-- | A header field is malformed.
InvalidHeader :: ToolkitError
-- | The start-line of the message and all header fields together exceed
-- the specified size Limit.
HeaderTooLarge :: ToolkitError
-- | The size of a body chunk exceeds maxChunkSize.
ChunkTooLarge :: ToolkitError
-- | A body chunk is malformed.
InvalidChunk :: ToolkitError
instance Typeable ToolkitError
instance Eq ToolkitError
instance Show ToolkitError
instance Exception ToolkitError
module Network.HTTP.Toolkit.Connection
-- | An abstract connection type that allows to read and unread input.
data Connection
Connection :: IO ByteString -> (ByteString -> IO ()) -> Connection
_read :: Connection -> IO ByteString
_unread :: Connection -> ByteString -> IO ()
-- | Create a Connection from provided IO action.
makeConnection :: IO ByteString -> IO Connection
-- | Create a Connection from provided Handle.
connectionFromHandle :: Handle -> IO Connection
-- | Read some input.
connectionRead :: Connection -> IO ByteString
-- | Push back some input. The pushed back input will be returned by a
-- later call to connectionRead.
connectionUnread :: Connection -> ByteString -> IO ()
-- | Read at least the specified number of bytes from the input stream.
connectionReadAtLeast :: Connection -> Int -> IO ByteString
module Network.HTTP.Toolkit.Header
-- | Message header size limit in bytes.
type Limit = Int
-- | Read start-line and message headers from provided Connection
-- (see RFC 2616, Section 4.1).
--
-- Throws:
--
--
-- - HeaderTooLarge if start-line and headers together exceed
-- the specified size Limit
-- - InvalidHeader if start-line is missing or a header is
-- malformed
--
readMessageHeader :: Limit -> Connection -> IO (ByteString, [Header])
-- | The default message header size limit of 65536 bytes (64 KB).
defaultHeaderSizeLimit :: Limit
-- | Parse header fields according to RFC 2616, Section 4.2.
parseHeaderFields :: [ByteString] -> Maybe [Header]
-- | Send given start-line and message headers.
--
-- Note: The first argument to this function is used to send the
-- data. For space efficiency it may be called multiple times.
sendHeader :: (ByteString -> IO ()) -> ByteString -> [Header] -> IO ()
readHeaderLines :: Limit -> Connection -> IO [ByteString]
combineHeaderLines :: [ByteString] -> [ByteString]
module Network.HTTP.Toolkit.Body
-- | 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.
type BodyReader = IO ByteString
data BodyType
-- | The message has no body.
None :: BodyType
-- | The message has a body. Chunked transfer coding is used to
-- determine the message length (see RFC 2616, Section 3.6.1).
Chunked :: BodyType
-- | The message has a body with a specified length.
Length :: Int -> BodyType
-- | 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.
Unlimited :: BodyType
-- | 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).
bodyTypeFromHeaders :: [Header] -> Maybe BodyType
-- | Create a BodyReader from provided Connection and
-- specified BodyType.
makeBodyReader :: Connection -> BodyType -> IO BodyReader
-- | Strictly consume all input from provided BodyReader.
consumeBody :: BodyReader -> IO ByteString
-- | 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.
sendBody :: (ByteString -> IO ()) -> BodyReader -> IO ()
-- | Create a BodyReader from provided ByteString.
fromByteString :: ByteString -> IO BodyReader
-- | The maximum size of a chunk in bytes when chunked transfer coding is
-- used. The value depends on the bitSize of Int:
--
--
-- - 2^28 on 32-bit systems
-- - 2^60 on 64-bit systems
--
maxChunkSize :: Int
-- | Create a reader for bodies with chunked transfer coding.
--
-- The reader throws:
--
--
makeChunkedReader :: Connection -> IO BodyReader
-- | Read size of next body chunk for when chunked transfer coding is used.
--
-- Throws:
--
--
readChunkSize :: Connection -> IO (Int, ByteString)
-- | Create a reader for bodies with a specified length.
makeLengthReader :: Int -> Connection -> IO BodyReader
-- | Create a reader for when the body length is determined by the server
-- closing the connection.
makeUnlimitedReader :: Connection -> IO BodyReader
instance Eq BodyType
instance Show BodyType
module Network.HTTP.Toolkit.Request
type RequestPath = ByteString
data Request a
Request :: Method -> RequestPath -> [Header] -> a -> Request a
requestMethod :: Request a -> Method
requestPath :: Request a -> RequestPath
requestHeaders :: Request a -> [Header]
requestBody :: Request a -> a
-- | Same as readRequestWithLimit with a Limit of
-- defaultHeaderSizeLimit.
readRequest :: Connection -> IO (Request BodyReader)
-- | Read request from provided connection.
--
-- Throws:
--
--
readRequestWithLimit :: Limit -> Connection -> IO (Request BodyReader)
-- | Parse request-line (see RFC 2616, Section 5.1).
parseRequestLine :: ByteString -> Maybe (Method, RequestPath)
-- | 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.
sendRequest :: (ByteString -> IO ()) -> Request BodyReader -> IO ()
-- | Format request-line.
formatRequestLine :: Method -> RequestPath -> ByteString
-- | Determine the message BodyType from a given list of message
-- headers (as of RFC 2616, Section 4.4).
determineRequestBodyType :: [Header] -> BodyType
instance Eq a => Eq (Request a)
instance Show a => Show (Request a)
instance Functor Request
module Network.HTTP.Toolkit.Response
data Response a
Response :: Status -> [Header] -> a -> Response a
responseStatus :: Response a -> Status
responseHeaders :: Response a -> [Header]
responseBody :: Response a -> a
-- | Same as readResponseWithLimit with a Limit of
-- defaultHeaderSizeLimit.
readResponse :: Method -> Connection -> IO (Response BodyReader)
-- | 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:
--
--
readResponseWithLimit :: Limit -> Method -> Connection -> IO (Response BodyReader)
-- | Parse status-line (see RFC 2616, Section 6.1).
parseStatusLine :: ByteString -> Maybe Status
-- | 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.
simpleResponse :: (ByteString -> IO ()) -> Status -> [Header] -> ByteString -> IO ()
-- | 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.
sendResponse :: (ByteString -> IO ()) -> (Response BodyReader) -> IO ()
-- | Format status-line.
formatStatusLine :: Status -> ByteString
-- | Determine the message BodyType from a given Method,
-- Status, and list of message headers (as of RFC 2616, Section
-- 4.4).
determineResponseBodyType :: Method -> Status -> [Header] -> BodyType
instance Eq a => Eq (Response a)
instance Show a => Show (Response a)
instance Functor Response
module Network.HTTP.Toolkit
-- | An abstract connection type that allows to read and unread input.
data Connection
-- | Create a Connection from provided IO action.
makeConnection :: IO ByteString -> IO Connection
-- | Create a Connection from provided Handle.
connectionFromHandle :: Handle -> IO Connection
data Request a
Request :: Method -> RequestPath -> [Header] -> a -> Request a
requestMethod :: Request a -> Method
requestPath :: Request a -> RequestPath
requestHeaders :: Request a -> [Header]
requestBody :: Request a -> a
-- | Read request from provided connection.
--
-- Throws:
--
--
readRequestWithLimit :: Limit -> Connection -> IO (Request BodyReader)
-- | Same as readRequestWithLimit with a Limit of
-- defaultHeaderSizeLimit.
readRequest :: Connection -> IO (Request BodyReader)
-- | 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.
sendRequest :: (ByteString -> IO ()) -> Request BodyReader -> IO ()
data Response a
Response :: Status -> [Header] -> a -> Response a
responseStatus :: Response a -> Status
responseHeaders :: Response a -> [Header]
responseBody :: Response a -> a
-- | 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:
--
--
readResponseWithLimit :: Limit -> Method -> Connection -> IO (Response BodyReader)
-- | Same as readResponseWithLimit with a Limit of
-- defaultHeaderSizeLimit.
readResponse :: Method -> Connection -> IO (Response BodyReader)
-- | 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.
sendResponse :: (ByteString -> IO ()) -> (Response BodyReader) -> IO ()
-- | 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.
simpleResponse :: (ByteString -> IO ()) -> Status -> [Header] -> ByteString -> IO ()
-- | 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.
type BodyReader = IO ByteString
-- | 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.
sendBody :: (ByteString -> IO ()) -> BodyReader -> IO ()
-- | Strictly consume all input from provided BodyReader.
consumeBody :: BodyReader -> IO ByteString
data ToolkitError
-- | The request-line of the message is malformed.
InvalidRequestLine :: ByteString -> ToolkitError
-- | The status-line of the message is malformed.
InvalidStatusLine :: ByteString -> ToolkitError
-- | A header field is malformed.
InvalidHeader :: ToolkitError
-- | The start-line of the message and all header fields together exceed
-- the specified size Limit.
HeaderTooLarge :: ToolkitError
-- | The size of a body chunk exceeds maxChunkSize.
ChunkTooLarge :: ToolkitError
-- | A body chunk is malformed.
InvalidChunk :: ToolkitError