-- 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.5.1
module Network.HTTP.Toolkit.Error
data ToolkitError
-- | The input ended unpexpectedly while reading a message.
UnexpectedEndOfInput :: 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
catchOnly :: (Eq e, Exception e) => IO a -> e -> IO a -> IO a
instance Typeable ToolkitError
instance Eq ToolkitError
instance Show ToolkitError
instance Exception ToolkitError
module Network.HTTP.Toolkit.InputStream
-- | An abstraction for input streams that allows to read and unread input.
data InputStream
InputStream :: IO ByteString -> (ByteString -> IO ()) -> InputStream
_read :: InputStream -> IO ByteString
_unread :: InputStream -> ByteString -> IO ()
-- | Create an InputStream from provided IO action.
makeInputStream :: IO ByteString -> IO InputStream
-- | Create an InputStream from provided Handle.
inputStreamFromHandle :: Handle -> IO InputStream
-- | Read some input.
readInput :: InputStream -> IO ByteString
-- | Push back some input. The pushed back input will be returned by a
-- later call to readInput.
unreadInput :: InputStream -> ByteString -> IO ()
-- | Read at least the specified number of bytes from the input stream.
readAtLeast :: InputStream -> Int -> IO ByteString
-- | Deprecated: use Network.HTTP.Toolkit.InputStream instead
--
module Network.HTTP.Toolkit.Connection
type Connection = InputStream
-- | An abstraction for input streams that allows to read and unread input.
data InputStream
InputStream :: IO ByteString -> (ByteString -> IO ()) -> InputStream
_read :: InputStream -> IO ByteString
_unread :: InputStream -> ByteString -> IO ()
makeConnection :: IO ByteString -> IO Connection
connectionFromHandle :: Handle -> IO Connection
connectionRead :: Connection -> IO ByteString
connectionUnread :: Connection -> ByteString -> IO ()
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 InputStream
-- (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 -> InputStream -> 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 -> InputStream -> 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 InputStream and
-- specified BodyType.
--
-- The first argument is passed to makeChunkedReader.
makeBodyReader :: Bool -> BodyType -> InputStream -> 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.
--
-- 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:
--
--
makeChunkedReader :: Bool -> InputStream -> IO BodyReader
-- | Read size of next body chunk for when chunked transfer coding is used.
--
-- Throws:
--
--
readChunkSize :: InputStream -> IO (Int, ByteString)
-- | Create a reader for bodies with a specified length.
makeLengthReader :: Int -> InputStream -> IO BodyReader
-- | Create a reader for when the body length is determined by the server
-- closing the connection.
makeUnlimitedReader :: InputStream -> 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 :: Bool -> InputStream -> IO (Request BodyReader)
-- | Read request from provided InputStream.
--
-- The second argument is passed to makeChunkedReader.
--
-- Throws:
--
--
readRequestWithLimit :: Limit -> Bool -> InputStream -> 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
instance Foldable Request
instance Traversable 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 :: Bool -> Method -> InputStream -> IO (Response BodyReader)
-- | 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:
--
--
readResponseWithLimit :: Limit -> Bool -> Method -> InputStream -> 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
instance Foldable Response
instance Traversable Response
module Network.HTTP.Toolkit
data ToolkitError
-- | The input ended unpexpectedly while reading a message.
UnexpectedEndOfInput :: 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
-- | An abstraction for input streams that allows to read and unread input.
data InputStream
-- | Create an InputStream from provided IO action.
makeInputStream :: IO ByteString -> IO InputStream
-- | Create an InputStream from provided Handle.
inputStreamFromHandle :: Handle -> IO InputStream
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
-- | Read request from provided InputStream.
--
-- The second argument is passed to makeChunkedReader.
--
-- Throws:
--
--
readRequestWithLimit :: Limit -> Bool -> InputStream -> IO (Request BodyReader)
-- | Same as readRequestWithLimit with a Limit of
-- defaultHeaderSizeLimit.
readRequest :: Bool -> InputStream -> 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 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:
--
--
readResponseWithLimit :: Limit -> Bool -> Method -> InputStream -> IO (Response BodyReader)
-- | Same as readResponseWithLimit with a Limit of
-- defaultHeaderSizeLimit.
readResponse :: Bool -> Method -> InputStream -> 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
type Connection = InputStream
makeConnection :: IO ByteString -> IO Connection
connectionFromHandle :: Handle -> IO Connection