http-types-0.12.3: Generic HTTP types for Haskell (for both client and server code).
Safe Haskell Safe-Inferred
Language Haskell98

Network.HTTP.Types

Synopsis

Methods

type Method = ByteString Source #

HTTP method (flat string type).

methodGet :: Method Source #

HTTP Method constants.

methodPost :: Method Source #

HTTP Method constants.

methodHead :: Method Source #

HTTP Method constants.

methodPut :: Method Source #

HTTP Method constants.

methodDelete :: Method Source #

HTTP Method constants.

methodTrace :: Method Source #

HTTP Method constants.

methodConnect :: Method Source #

HTTP Method constants.

methodOptions :: Method Source #

HTTP Method constants.

methodPatch :: Method Source #

HTTP Method constants.

data StdMethod Source #

HTTP standard method (as defined by RFC 2616, and PATCH which is defined by RFC 5789).

Instances

Instances details
Bounded StdMethod Source #
Instance details

Defined in Network.HTTP.Types.Method

Enum StdMethod Source #
Instance details

Defined in Network.HTTP.Types.Method

Eq StdMethod Source #
Instance details

Defined in Network.HTTP.Types.Method

Ord StdMethod Source #
Instance details

Defined in Network.HTTP.Types.Method

Read StdMethod Source #
Instance details

Defined in Network.HTTP.Types.Method

Show StdMethod Source #
Instance details

Defined in Network.HTTP.Types.Method

Ix StdMethod Source #
Instance details

Defined in Network.HTTP.Types.Method

renderMethod :: Either ByteString StdMethod -> Method Source #

Convert an algebraic method to a ByteString .

Versions

Status

data Status Source #

HTTP Status.

Only the statusCode is used for comparisons.

Please use mkStatus to create status codes from code and message, or the Enum instance or the status code constants (like ok200 ). There might be additional record members in the future.

Note that the Show instance is only for debugging.

mkStatus :: Int -> ByteString -> Status Source #

Create a Status from status code and message.

status101 :: Status Source #

Switching Protocols 101

status203 :: Status Source #

Non-Authoritative Information 203

nonAuthoritative203 :: Status Source #

Non-Authoritative Information 203

status206 :: Status Source #

Partial Content 206

status300 :: Status Source #

Multiple Choices 300

status301 :: Status Source #

Moved Permanently 301

status307 :: Status Source #

Temporary Redirect 307

status308 :: Status Source #

Permanent Redirect 308

status402 :: Status Source #

Payment Required 402

status405 :: Status Source #

Method Not Allowed 405

status407 :: Status Source #

Proxy Authentication Required 407

proxyAuthenticationRequired407 :: Status Source #

Proxy Authentication Required 407

status408 :: Status Source #

Request Timeout 408

status411 :: Status Source #

Length Required 411

status412 :: Status Source #

Precondition Failed 412

status413 :: Status Source #

Request Entity Too Large 413

status414 :: Status Source #

Request-URI Too Long 414

status415 :: Status Source #

Unsupported Media Type 415

status416 :: Status Source #

Requested Range Not Satisfiable 416

requestedRangeNotSatisfiable416 :: Status Source #

Requested Range Not Satisfiable 416

status417 :: Status Source #

Expectation Failed 417

status422 :: Status Source #

Unprocessable Entity 422 ( RFC 4918 )

status428 :: Status Source #

Precondition Required 428 ( RFC 6585 )

status431 :: Status Source #

Request Header Fields Too Large 431 ( RFC 6585 )

status500 :: Status Source #

Internal Server Error 500

status501 :: Status Source #

Not Implemented 501

status503 :: Status Source #

Service Unavailable 503

status504 :: Status Source #

Gateway Timeout 504

status505 :: Status Source #

HTTP Version Not Supported 505

status511 :: Status Source #

Network Authentication Required 511 ( RFC 6585 )

Headers

Types

type RequestHeaders = [ Header ] Source #

Request Headers

type ResponseHeaders = [ Header ] Source #

Response Headers

Common headers

Byte ranges

data ByteRange Source #

RFC 2616 Byte range (individual).

Negative indices are not allowed!

Instances

Instances details
Eq ByteRange Source #
Instance details

Defined in Network.HTTP.Types.Header

Data ByteRange Source #
Instance details

Defined in Network.HTTP.Types.Header

Methods

gfoldl :: ( forall d b. Data d => c (d -> b) -> d -> c b) -> ( forall g. g -> c g) -> ByteRange -> c ByteRange Source #

gunfold :: ( forall b r. Data b => c (b -> r) -> c r) -> ( forall r. r -> c r) -> Constr -> c ByteRange Source #

toConstr :: ByteRange -> Constr Source #

dataTypeOf :: ByteRange -> DataType Source #

dataCast1 :: Typeable t => ( forall d. Data d => c (t d)) -> Maybe (c ByteRange ) Source #

dataCast2 :: Typeable t => ( forall d e. ( Data d, Data e) => c (t d e)) -> Maybe (c ByteRange ) Source #

gmapT :: ( forall b. Data b => b -> b) -> ByteRange -> ByteRange Source #

gmapQl :: (r -> r' -> r) -> r -> ( forall d. Data d => d -> r') -> ByteRange -> r Source #

gmapQr :: forall r r'. (r' -> r -> r) -> r -> ( forall d. Data d => d -> r') -> ByteRange -> r Source #

gmapQ :: ( forall d. Data d => d -> u) -> ByteRange -> [u] Source #

gmapQi :: Int -> ( forall d. Data d => d -> u) -> ByteRange -> u Source #

gmapM :: Monad m => ( forall d. Data d => d -> m d) -> ByteRange -> m ByteRange Source #

gmapMp :: MonadPlus m => ( forall d. Data d => d -> m d) -> ByteRange -> m ByteRange Source #

gmapMo :: MonadPlus m => ( forall d. Data d => d -> m d) -> ByteRange -> m ByteRange Source #

Ord ByteRange Source #
Instance details

Defined in Network.HTTP.Types.Header

Show ByteRange Source #
Instance details

Defined in Network.HTTP.Types.Header

type ByteRanges = [ ByteRange ] Source #

RFC 2616 Byte ranges (set).

parseByteRanges :: ByteString -> Maybe ByteRanges Source #

Parse the value of a Range header into a ByteRanges .

>>> parseByteRanges "error"
Nothing
>>> parseByteRanges "bytes=0-499"
Just [ByteRangeFromTo 0 499]
>>> parseByteRanges "bytes=500-999"
Just [ByteRangeFromTo 500 999]
>>> parseByteRanges "bytes=-500"
Just [ByteRangeSuffix 500]
>>> parseByteRanges "bytes=9500-"
Just [ByteRangeFrom 9500]
>>> parseByteRanges "bytes=0-0,-1"
Just [ByteRangeFromTo 0 0,ByteRangeSuffix 1]
>>> parseByteRanges "bytes=500-600,601-999"
Just [ByteRangeFromTo 500 600,ByteRangeFromTo 601 999]
>>> parseByteRanges "bytes=500-700,601-999"
Just [ByteRangeFromTo 500 700,ByteRangeFromTo 601 999]

URI

Query string

type Query = [ QueryItem ] Source #

Query.

General form: a=b&c=d , but if the value is Nothing, it becomes a&c=d .

type SimpleQueryItem = ( ByteString , ByteString ) Source #

Simplified Query item type without support for parameter-less items.

type SimpleQuery = [ SimpleQueryItem ] Source #

Simplified Query type without support for parameter-less items.

renderQuery Source #

Arguments

:: Bool

prepend question mark?

-> Query
-> ByteString

Convert Query to ByteString .

renderQueryBuilder Source #

Arguments

:: Bool

prepend a question mark?

-> Query
-> Builder

Convert Query to a Builder .

renderSimpleQuery Source #

Arguments

:: Bool

prepend question mark?

-> SimpleQuery
-> ByteString

Convert SimpleQuery to ByteString .

parseQuery :: ByteString -> Query Source #

Split out the query string into a list of keys and values. A few importants points:

  • The result returned is still bytestrings, since we perform no character decoding here. Most likely, you will want to use UTF-8 decoding, but this is left to the user of the library.
  • Percent decoding errors are ignored. In particular, "%Q" will be output as "%Q" .
  • It decodes '+' characters to ' '

Escape only parts

type PartialEscapeQuery = [ PartialEscapeQueryItem ] Source #

Query with some chars that should not be escaped.

General form: a=b&c=d:e+f&g=h

Text query string (UTF8 encoded)

type QueryText = [( Text , Maybe Text )] Source #

Like Query, but with Text instead of ByteString (UTF8-encoded).

renderQueryText Source #

Arguments

:: Bool

prepend a question mark?

-> QueryText
-> Builder

Convert QueryText to a Builder .

Generalized query types

class QueryLike a where Source #

Types which can, and commonly are, converted to Query are in this class.

You can use lists of simple key value pairs, with ByteString (strict, or lazy: ByteString ), Text , or String as the key/value types. You can also have the value type lifted into a Maybe to support keys without values; and finally it is possible to put each pair into a Maybe for key-value pairs that aren't always present.

Methods

toQuery :: a -> Query Source #

Convert to Query .

Path segments

encodePathSegments :: [ Text ] -> Builder Source #

Encodes a list of path segments into a valid URL fragment.

This function takes the following three steps:

  • UTF-8 encodes the characters.
  • Performs percent encoding on all unreserved characters, as well as :@=+$ ,
  • Prepends each segment with a slash.

For example:

encodePathSegments [\"foo\", \"bar\", \"baz\"]

"/foo/bar/baz"

encodePathSegments [\"foo bar\", \"baz\/bin\"]

"/foo%20bar/baz%2Fbin"

encodePathSegments [\"שלום\"]

"/%D7%A9%D7%9C%D7%95%D7%9D"

Huge thanks to Jeremy Shaw who created the original implementation of this function in web-routes and did such thorough research to determine all correct escaping procedures.

decodePathSegments :: ByteString -> [ Text ] Source #

Parse a list of path segments from a valid URL fragment.

encodePathSegmentsRelative :: [ Text ] -> Builder Source #

Like encodePathSegments, but without the initial slash.

Path (segments + query string)

extractPath :: ByteString -> ByteString Source #

Extract whole path (path segments + query) from a RFC 2616 Request-URI .

>>> extractPath "/path"
"/path"
>>> extractPath "http://example.com:8080/path"
"/path"
>>> extractPath "http://example.com"
"/"
>>> extractPath ""
"/"

encodePath :: [ Text ] -> Query -> Builder Source #

Encode a whole path (path segments + query).

decodePath :: ByteString -> ([ Text ], Query ) Source #

Decode a whole path (path segments + query).

URL encoding / decoding

urlEncodeBuilder Source #

Arguments

:: Bool

Whether input is in query string. True: Query string, False: Path element

-> ByteString
-> Builder

Percent-encoding for URLs (using Builder ).

urlEncode Source #

Arguments

:: Bool

Whether to decode '+' to ' '

-> ByteString

The ByteString to encode as URL

-> ByteString

The encoded URL

Percent-encoding for URLs.

urlDecode Source #

Arguments

:: Bool

Whether to decode '+' to ' '

-> ByteString
-> ByteString

Percent-decoding.