-- 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
-- HTTP 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 with constant space usage.
-- - universal No framework for streaming data is used. This
-- allows you to build more sophisticated application on top of it, using
-- the libraries that fit your purpose.
--
@package http-kit
@version 0.1.0
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
-- | 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.Error
data ToolkitError
-- | Parsing of HTTP request-line failed.
InvalidRequestLine :: ByteString -> ToolkitError
-- | Parsing of HTTP status-line failed.
InvalidStatusLine :: ByteString -> ToolkitError
-- | A header field is malformed.
InvalidHeader :: ToolkitError
-- | The message header exceeds the specified 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.Header
-- | An HTTP message header consiting of a start line and a list of header
-- fields.
data MessageHeader a
MessageHeader :: a -> [Header] -> MessageHeader a
-- | Message header size limit in bytes.
type Limit = Int
-- | Read MessageHeader from provided Connection.
--
-- Throws:
--
--
readMessageHeader :: Connection -> IO (MessageHeader ByteString)
-- | Read MessageHeader from provided Connection.
--
-- Throws:
--
--
readMessageHeaderWithLimit :: Limit -> Connection -> IO (MessageHeader ByteString)
-- | 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]
readHeaderLines :: Limit -> Connection -> IO [ByteString]
combineHeaderLines :: [ByteString] -> [ByteString]
instance Eq a => Eq (MessageHeader a)
instance Show a => Show (MessageHeader a)
instance Functor MessageHeader
instance Foldable MessageHeader
instance Traversable MessageHeader
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.
sendBody :: (ByteString -> IO ()) -> BodyReader -> IO ()
-- | 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
type RequestHeader = MessageHeader (Method, RequestPath)
-- | Same as readRequestWithLimit with a Limit of
-- defaultHeaderSizeLimit.
readRequest :: Connection -> IO (RequestHeader, BodyReader)
-- | Read request from provided connection.
--
-- Throws:
--
--
readRequestWithLimit :: Limit -> Connection -> IO (RequestHeader, BodyReader)
-- | Parse request-line (see RFC 2616, Section 5.1).
parseRequestLine :: ByteString -> Maybe (Method, RequestPath)
-- | Determine the message BodyType from a given list of message
-- headers (as of RFC 2616, Section 4.4).
determineRequestBodyType :: [Header] -> BodyType
module Network.HTTP.Toolkit.Response
type ResponseHeader = MessageHeader Status
-- | Same as readResponseWithLimit with a Limit of
-- defaultHeaderSizeLimit.
readResponse :: Method -> Connection -> IO (ResponseHeader, BodyReader)
-- | Read response from provided connection.
--
-- Throws:
--
--
readResponseWithLimit :: Limit -> Method -> Connection -> IO (ResponseHeader, BodyReader)
-- | Parse status-line (see RFC 2616, Section 6.1).
parseStatusLine :: ByteString -> Maybe Status
-- | 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