Network.HTTP.Types

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

Contents

- Methods
- Versions
- Status
- Headers
  - Types
  - Common headers
  - Byte ranges
- URI
  - Query string
  - Escape only parts
    - Text query string (UTF8 encoded)
  - Generalized query types
  - Path segments
  - Path (segments + query string)
  - URL encoding / decoding

Synopsis

- type Method = ByteString
- methodGet :: Method
- methodPost :: Method
- methodHead :: Method
- methodPut :: Method
- methodDelete :: Method
- methodTrace :: Method
- methodConnect :: Method
- methodOptions :: Method
- methodPatch :: Method
- data StdMethod
  - = GET
  - | POST
  - | HEAD
  - | PUT
  - | DELETE
  - | TRACE
  - | CONNECT
  - | OPTIONS
  - | PATCH
- parseMethod :: Method -> Either ByteString StdMethod
- renderMethod :: Either ByteString StdMethod -> Method
- renderStdMethod :: StdMethod -> Method
- data HttpVersion = HttpVersion {
  - httpMajor :: !Int
  - httpMinor :: !Int
  }
- http09 :: HttpVersion
- http10 :: HttpVersion
- http11 :: HttpVersion
- http20 :: HttpVersion
- data Status = Status {
  - statusCode :: Int
  - statusMessage :: ByteString
  }
- mkStatus :: Int -> ByteString -> Status
- status100 :: Status
- continue100 :: Status
- status101 :: Status
- switchingProtocols101 :: Status
- status200 :: Status
- ok200 :: Status
- status201 :: Status
- created201 :: Status
- status202 :: Status
- accepted202 :: Status
- status203 :: Status
- nonAuthoritative203 :: Status
- status204 :: Status
- noContent204 :: Status
- status205 :: Status
- resetContent205 :: Status
- status206 :: Status
- partialContent206 :: Status
- status300 :: Status
- multipleChoices300 :: Status
- status301 :: Status
- movedPermanently301 :: Status
- status302 :: Status
- found302 :: Status
- status303 :: Status
- seeOther303 :: Status
- status304 :: Status
- notModified304 :: Status
- status305 :: Status
- useProxy305 :: Status
- status307 :: Status
- temporaryRedirect307 :: Status
- status308 :: Status
- permanentRedirect308 :: Status
- status400 :: Status
- badRequest400 :: Status
- status401 :: Status
- unauthorized401 :: Status
- status402 :: Status
- paymentRequired402 :: Status
- status403 :: Status
- forbidden403 :: Status
- status404 :: Status
- notFound404 :: Status
- status405 :: Status
- methodNotAllowed405 :: Status
- status406 :: Status
- notAcceptable406 :: Status
- status407 :: Status
- proxyAuthenticationRequired407 :: Status
- status408 :: Status
- requestTimeout408 :: Status
- status409 :: Status
- conflict409 :: Status
- status410 :: Status
- gone410 :: Status
- status411 :: Status
- lengthRequired411 :: Status
- status412 :: Status
- preconditionFailed412 :: Status
- status413 :: Status
- requestEntityTooLarge413 :: Status
- status414 :: Status
- requestURITooLong414 :: Status
- status415 :: Status
- unsupportedMediaType415 :: Status
- status416 :: Status
- requestedRangeNotSatisfiable416 :: Status
- status417 :: Status
- expectationFailed417 :: Status
- status418 :: Status
- imATeapot418 :: Status
- status422 :: Status
- unprocessableEntity422 :: Status
- status428 :: Status
- preconditionRequired428 :: Status
- status429 :: Status
- tooManyRequests429 :: Status
- status431 :: Status
- requestHeaderFieldsTooLarge431 :: Status
- status500 :: Status
- internalServerError500 :: Status
- status501 :: Status
- notImplemented501 :: Status
- status502 :: Status
- badGateway502 :: Status
- status503 :: Status
- serviceUnavailable503 :: Status
- status504 :: Status
- gatewayTimeout504 :: Status
- status505 :: Status
- httpVersionNotSupported505 :: Status
- status511 :: Status
- networkAuthenticationRequired511 :: Status
- statusIsInformational :: Status -> Bool
- statusIsSuccessful :: Status -> Bool
- statusIsRedirection :: Status -> Bool
- statusIsClientError :: Status -> Bool
- statusIsServerError :: Status -> Bool
- type Header = (HeaderName, ByteString)
- type HeaderName = CI ByteString
- type RequestHeaders = [Header]
- type ResponseHeaders = [Header]
- hAccept :: HeaderName
- hAcceptLanguage :: HeaderName
- hAuthorization :: HeaderName
- hCacheControl :: HeaderName
- hCookie :: HeaderName
- hConnection :: HeaderName
- hContentEncoding :: HeaderName
- hContentLength :: HeaderName
- hContentMD5 :: HeaderName
- hContentType :: HeaderName
- hDate :: HeaderName
- hIfModifiedSince :: HeaderName
- hIfRange :: HeaderName
- hLastModified :: HeaderName
- hLocation :: HeaderName
- hRange :: HeaderName
- hReferer :: HeaderName
- hServer :: HeaderName
- hUserAgent :: HeaderName
- data ByteRange
  - = ByteRangeFrom !Integer
  - | ByteRangeFromTo !Integer !Integer
  - | ByteRangeSuffix !Integer
- renderByteRangeBuilder :: ByteRange -> Builder
- renderByteRange :: ByteRange -> ByteString
- type ByteRanges = [ByteRange]
- renderByteRangesBuilder :: ByteRanges -> Builder
- renderByteRanges :: ByteRanges -> ByteString
- parseByteRanges :: ByteString -> Maybe ByteRanges
- type QueryItem = (ByteString, Maybe ByteString)
- type Query = [QueryItem]
- type SimpleQueryItem = (ByteString, ByteString)
- type SimpleQuery = [SimpleQueryItem]
- simpleQueryToQuery :: SimpleQuery -> Query
- renderQuery :: Bool -> Query -> ByteString
- renderQueryBuilder :: Bool -> Query -> Builder
- renderSimpleQuery :: Bool -> SimpleQuery -> ByteString
- parseQuery :: ByteString -> Query
- parseSimpleQuery :: ByteString -> SimpleQuery
- renderQueryPartialEscape :: Bool -> PartialEscapeQuery -> ByteString
- renderQueryBuilderPartialEscape :: Bool -> PartialEscapeQuery -> Builder
- data EscapeItem
  - = QE ByteString
  - | QN ByteString
- type PartialEscapeQueryItem = (ByteString, [EscapeItem])
- type PartialEscapeQuery = [PartialEscapeQueryItem]
- type QueryText = [(Text, Maybe Text)]
- queryTextToQuery :: QueryText -> Query
- queryToQueryText :: Query -> QueryText
- renderQueryText :: Bool -> QueryText -> Builder
- parseQueryText :: ByteString -> QueryText
- class QueryLike a where
  - toQuery :: a -> Query
- encodePathSegments :: [Text] -> Builder
- decodePathSegments :: ByteString -> [Text]
- encodePathSegmentsRelative :: [Text] -> Builder
- extractPath :: ByteString -> ByteString
- encodePath :: [Text] -> Query -> Builder
- decodePath :: ByteString -> ([Text], Query)
- urlEncodeBuilder :: Bool -> ByteString -> Builder
- urlEncode :: Bool -> ByteString -> ByteString
- urlDecode :: Bool -> ByteString -> ByteString

# Methods

type Method = ByteString #

HTTP method (flat string type).

methodGet :: Method #

HTTP Method constants.

methodPost :: Method #

HTTP Method constants.

methodHead :: Method #

HTTP Method constants.

methodPut :: Method #

HTTP Method constants.

methodDelete :: Method #

HTTP Method constants.

methodTrace :: Method #

HTTP Method constants.

methodConnect :: Method #

HTTP Method constants.

methodOptions :: Method #

HTTP Method constants.

methodPatch :: Method #

HTTP Method constants.

data StdMethod #

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

Constructors

GET |
POST |
HEAD |
PUT |
DELETE |
TRACE |
CONNECT |
OPTIONS |
PATCH |

#### Instances

Instances details

Bounded StdMethod # |
Instance details Defined in Network.HTTP.Types.Method Methods minBound :: StdMethod maxBound :: StdMethod
Enum StdMethod # |
Instance details Defined in Network.HTTP.Types.Method Methods succ :: StdMethod -> StdMethod pred :: StdMethod -> StdMethod toEnum :: Int -> StdMethod fromEnum :: StdMethod -> Int enumFrom :: StdMethod -> [StdMethod] enumFromThen :: StdMethod -> StdMethod -> [StdMethod] enumFromTo :: StdMethod -> StdMethod -> [StdMethod] enumFromThenTo :: StdMethod -> StdMethod -> StdMethod -> [StdMethod]
Ix StdMethod # |
Instance details Defined in Network.HTTP.Types.Method Methods range :: (StdMethod, StdMethod) -> [StdMethod] index :: (StdMethod, StdMethod) -> StdMethod -> Int unsafeIndex :: (StdMethod, StdMethod) -> StdMethod -> Int inRange :: (StdMethod, StdMethod) -> StdMethod -> Bool rangeSize :: (StdMethod, StdMethod) -> Int unsafeRangeSize :: (StdMethod, StdMethod) -> Int
Read StdMethod # |
Instance details Defined in Network.HTTP.Types.Method Methods readsPrec :: Int -> ReadS StdMethod readList :: ReadS [StdMethod] readPrec :: ReadPrec StdMethod readListPrec :: ReadPrec [StdMethod]
Show StdMethod # |
Instance details Defined in Network.HTTP.Types.Method Methods showsPrec :: Int -> StdMethod -> ShowS show :: StdMethod -> String showList :: [StdMethod] -> ShowS
Eq StdMethod # |
Instance details Defined in Network.HTTP.Types.Method Methods (==) :: StdMethod -> StdMethod -> Bool (/=) :: StdMethod -> StdMethod -> Bool
Ord StdMethod # |
Instance details Defined in Network.HTTP.Types.Method Methods compare :: StdMethod -> StdMethod -> Ordering (<) :: StdMethod -> StdMethod -> Bool (<=) :: StdMethod -> StdMethod -> Bool (>) :: StdMethod -> StdMethod -> Bool (>=) :: StdMethod -> StdMethod -> Bool max :: StdMethod -> StdMethod -> StdMethod min :: StdMethod -> StdMethod -> StdMethod

parseMethod :: Method -> Either ByteString StdMethod #

Convert a method `ByteString` to a `StdMethod` if possible.

renderMethod :: Either ByteString StdMethod -> Method #

Convert an algebraic method to a `ByteString`.

renderStdMethod :: StdMethod -> Method #

Convert a `StdMethod` to a `ByteString`.

# Versions

data HttpVersion #

HTTP Version.

Note that the Show instance is intended merely for debugging.

Constructors

HttpVersion |
Fields httpMajor :: !Int httpMinor :: !Int

#### Instances

Instances details

Show HttpVersion # |
Instance details Defined in Network.HTTP.Types.Version Methods showsPrec :: Int -> HttpVersion -> ShowS show :: HttpVersion -> String showList :: [HttpVersion] -> ShowS
Eq HttpVersion # |
Instance details Defined in Network.HTTP.Types.Version Methods (==) :: HttpVersion -> HttpVersion -> Bool (/=) :: HttpVersion -> HttpVersion -> Bool
Ord HttpVersion # |
Instance details Defined in Network.HTTP.Types.Version Methods compare :: HttpVersion -> HttpVersion -> Ordering (<) :: HttpVersion -> HttpVersion -> Bool (<=) :: HttpVersion -> HttpVersion -> Bool (>) :: HttpVersion -> HttpVersion -> Bool (>=) :: HttpVersion -> HttpVersion -> Bool max :: HttpVersion -> HttpVersion -> HttpVersion min :: HttpVersion -> HttpVersion -> HttpVersion

http09 :: HttpVersion #

HTTP 0.9

http10 :: HttpVersion #

HTTP 1.0

http11 :: HttpVersion #

HTTP 1.1

http20 :: HttpVersion #

HTTP 2.0

# Status

data Status #

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.

Constructors

Status |
Fields statusCode :: Int statusMessage :: ByteString

#### Instances

Instances details

Bounded Status # |
Instance details Defined in Network.HTTP.Types.Status Methods minBound :: Status maxBound :: Status
Enum Status # |
Instance details Defined in Network.HTTP.Types.Status Methods succ :: Status -> Status pred :: Status -> Status toEnum :: Int -> Status fromEnum :: Status -> Int enumFrom :: Status -> [Status] enumFromThen :: Status -> Status -> [Status] enumFromTo :: Status -> Status -> [Status] enumFromThenTo :: Status -> Status -> Status -> [Status]
Show Status # |
Instance details Defined in Network.HTTP.Types.Status Methods showsPrec :: Int -> Status -> ShowS show :: Status -> String showList :: [Status] -> ShowS
Eq Status # |
Instance details Defined in Network.HTTP.Types.Status Methods (==) :: Status -> Status -> Bool (/=) :: Status -> Status -> Bool
Ord Status # |
Instance details Defined in Network.HTTP.Types.Status Methods compare :: Status -> Status -> Ordering (<) :: Status -> Status -> Bool (<=) :: Status -> Status -> Bool (>) :: Status -> Status -> Bool (>=) :: Status -> Status -> Bool max :: Status -> Status -> Status min :: Status -> Status -> Status

mkStatus :: Int -> ByteString -> Status #

Create a Status from status code and message.

status100 :: Status #

Continue 100

continue100 :: Status #

Continue 100

status101 :: Status #

Switching Protocols 101

switchingProtocols101 :: Status #

Switching Protocols 101

status200 :: Status #

OK 200

ok200 :: Status #

OK 200

status201 :: Status #

Created 201

created201 :: Status #

Created 201

status202 :: Status #

Accepted 202

accepted202 :: Status #

Accepted 202

status203 :: Status #

Non-Authoritative Information 203

nonAuthoritative203 :: Status #

Non-Authoritative Information 203

status204 :: Status #

No Content 204

noContent204 :: Status #

No Content 204

status205 :: Status #

Reset Content 205

resetContent205 :: Status #

Reset Content 205

status206 :: Status #

Partial Content 206

partialContent206 :: Status #

Partial Content 206

status300 :: Status #

Multiple Choices 300

multipleChoices300 :: Status #

Multiple Choices 300

status301 :: Status #

Moved Permanently 301

movedPermanently301 :: Status #

Moved Permanently 301

status302 :: Status #

Found 302

found302 :: Status #

Found 302

status303 :: Status #

See Other 303

seeOther303 :: Status #

See Other 303

status304 :: Status #

Not Modified 304

notModified304 :: Status #

Not Modified 304

status305 :: Status #

Use Proxy 305

useProxy305 :: Status #

Use Proxy 305

status307 :: Status #

Temporary Redirect 307

temporaryRedirect307 :: Status #

Temporary Redirect 307

status308 :: Status #

Permanent Redirect 308

permanentRedirect308 :: Status #

Permanent Redirect 308

status400 :: Status #

Bad Request 400

badRequest400 :: Status #

Bad Request 400

status401 :: Status #

Unauthorized 401

unauthorized401 :: Status #

Unauthorized 401

status402 :: Status #

Payment Required 402

paymentRequired402 :: Status #

Payment Required 402

status403 :: Status #

Forbidden 403

forbidden403 :: Status #

Forbidden 403

status404 :: Status #

Not Found 404

notFound404 :: Status #

Not Found 404

status405 :: Status #

Method Not Allowed 405

methodNotAllowed405 :: Status #

Method Not Allowed 405

status406 :: Status #

Not Acceptable 406

notAcceptable406 :: Status #

Not Acceptable 406

status407 :: Status #

Proxy Authentication Required 407

proxyAuthenticationRequired407 :: Status #

Proxy Authentication Required 407

status408 :: Status #

Request Timeout 408

requestTimeout408 :: Status #

Request Timeout 408

status409 :: Status #

Conflict 409

conflict409 :: Status #

Conflict 409

status410 :: Status #

Gone 410

gone410 :: Status #

Gone 410

status411 :: Status #

Length Required 411

lengthRequired411 :: Status #

Length Required 411

status412 :: Status #

Precondition Failed 412

preconditionFailed412 :: Status #

Precondition Failed 412

status413 :: Status #

Request Entity Too Large 413

requestEntityTooLarge413 :: Status #

Request Entity Too Large 413

status414 :: Status #

Request-URI Too Long 414

requestURITooLong414 :: Status #

Request-URI Too Long 414

status415 :: Status #

Unsupported Media Type 415

unsupportedMediaType415 :: Status #

Unsupported Media Type 415

status416 :: Status #

Requested Range Not Satisfiable 416

requestedRangeNotSatisfiable416 :: Status #

Requested Range Not Satisfiable 416

status417 :: Status #

Expectation Failed 417

expectationFailed417 :: Status #

Expectation Failed 417

status418 :: Status #

I'm a teapot 418

imATeapot418 :: Status #

I'm a teapot 418

status422 :: Status #

Unprocessable Entity 422 (RFC 4918)

unprocessableEntity422 :: Status #

Unprocessable Entity 422 (RFC 4918)

status428 :: Status #

Precondition Required 428 (RFC 6585)

preconditionRequired428 :: Status #

Precondition Required 428 (RFC 6585)

status429 :: Status #

Too Many Requests 429 (RFC 6585)

tooManyRequests429 :: Status #

Too Many Requests 429 (RFC 6585)

status431 :: Status #

Request Header Fields Too Large 431 (RFC 6585)

requestHeaderFieldsTooLarge431 :: Status #

Request Header Fields Too Large 431 (RFC 6585)

status500 :: Status #

Internal Server Error 500

internalServerError500 :: Status #

Internal Server Error 500

status501 :: Status #

Not Implemented 501

notImplemented501 :: Status #

Not Implemented 501

status502 :: Status #

Bad Gateway 502

badGateway502 :: Status #

Bad Gateway 502

status503 :: Status #

Service Unavailable 503

serviceUnavailable503 :: Status #

Service Unavailable 503

status504 :: Status #

Gateway Timeout 504

gatewayTimeout504 :: Status #

Gateway Timeout 504

status505 :: Status #

HTTP Version Not Supported 505

httpVersionNotSupported505 :: Status #

HTTP Version Not Supported 505

status511 :: Status #

Network Authentication Required 511 (RFC 6585)

networkAuthenticationRequired511 :: Status #

Network Authentication Required 511 (RFC 6585)

statusIsInformational :: Status -> Bool #

Informational class

statusIsSuccessful :: Status -> Bool #

Successful class

statusIsRedirection :: Status -> Bool #

Redirection class

statusIsClientError :: Status -> Bool #

Client Error class

statusIsServerError :: Status -> Bool #

Server Error class

# Headers

## Types

type Header = (HeaderName, ByteString) #

Header

type HeaderName = CI ByteString #

Header name

type RequestHeaders = [Header] #

Request Headers

type ResponseHeaders = [Header] #

Response Headers

## Common headers

hAccept :: HeaderName #

HTTP Header names according to http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html

hAcceptLanguage :: HeaderName #

HTTP Header names according to http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html

hAuthorization :: HeaderName #

HTTP Header names according to http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html

hCacheControl :: HeaderName #

HTTP Header names according to http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html

hCookie :: HeaderName #

HTTP Header names according to https://tools.ietf.org/html/rfc6265#section-4

hConnection :: HeaderName #

HTTP Header names according to http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html

hContentEncoding :: HeaderName #

HTTP Header names according to http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html

hContentLength :: HeaderName #

HTTP Header names according to http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html

hContentMD5 :: HeaderName #

HTTP Header names according to http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html

hContentType :: HeaderName #

HTTP Header names according to http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html

hDate :: HeaderName #

HTTP Header names according to http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html

hIfModifiedSince :: HeaderName #

HTTP Header names according to http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html

hIfRange :: HeaderName #

HTTP Header names according to http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html

hLastModified :: HeaderName #

HTTP Header names according to http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html

hLocation :: HeaderName #

HTTP Header names according to http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html

hRange :: HeaderName #

HTTP Header names according to http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html

hReferer :: HeaderName #

HTTP Header names according to http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html

hServer :: HeaderName #

HTTP Header names according to http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html

hUserAgent :: HeaderName #

HTTP Header names according to http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html

## Byte ranges

data ByteRange #

RFC 2616 Byte range (individual).

Negative indices are not allowed!

Constructors

ByteRangeFrom !Integer |
ByteRangeFromTo !Integer !Integer |
ByteRangeSuffix !Integer |

#### Instances

Instances details

Data ByteRange # |
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 gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c ByteRange toConstr :: ByteRange -> Constr dataTypeOf :: ByteRange -> DataType dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c ByteRange) dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c ByteRange) gmapT :: (forall b. Data b => b -> b) -> ByteRange -> ByteRange gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> ByteRange -> r gmapQr :: forall r r'. (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> ByteRange -> r gmapQ :: (forall d. Data d => d -> u) -> ByteRange -> [u] gmapQi :: Int -> (forall d. Data d => d -> u) -> ByteRange -> u gmapM :: Monad m => (forall d. Data d => d -> m d) -> ByteRange -> m ByteRange gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> ByteRange -> m ByteRange gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> ByteRange -> m ByteRange
Show ByteRange # |
Instance details Defined in Network.HTTP.Types.Header Methods showsPrec :: Int -> ByteRange -> ShowS show :: ByteRange -> String showList :: [ByteRange] -> ShowS
Eq ByteRange # |
Instance details Defined in Network.HTTP.Types.Header Methods (==) :: ByteRange -> ByteRange -> Bool (/=) :: ByteRange -> ByteRange -> Bool
Ord ByteRange # |
Instance details Defined in Network.HTTP.Types.Header Methods compare :: ByteRange -> ByteRange -> Ordering (<) :: ByteRange -> ByteRange -> Bool (<=) :: ByteRange -> ByteRange -> Bool (>) :: ByteRange -> ByteRange -> Bool (>=) :: ByteRange -> ByteRange -> Bool max :: ByteRange -> ByteRange -> ByteRange min :: ByteRange -> ByteRange -> ByteRange

renderByteRangeBuilder :: ByteRange -> Builder #

renderByteRange :: ByteRange -> ByteString #

type ByteRanges = [ByteRange] #

RFC 2616 Byte ranges (set).

renderByteRangesBuilder :: ByteRanges -> Builder #

renderByteRanges :: ByteRanges -> ByteString #

parseByteRanges :: ByteString -> Maybe ByteRanges #

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 QueryItem = (ByteString, Maybe ByteString) #

Query item

type Query = [QueryItem] #

Query.

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

type SimpleQueryItem = (ByteString, ByteString) #

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

type SimpleQuery = [SimpleQueryItem] #

Simplified Query type without support for parameter-less items.

simpleQueryToQuery :: SimpleQuery -> Query #

Convert `SimpleQuery` to `Query`.

renderQuery #

Arguments

:: Bool | prepend question mark?
-> Query |
-> ByteString |

Convert `Query` to `ByteString`.

renderQueryBuilder #

Arguments

:: Bool | prepend a question mark?
-> Query |
-> Builder |

Convert `Query` to a `Builder`.

renderSimpleQuery #

Arguments

:: Bool | prepend question mark?
-> SimpleQuery |
-> ByteString |

Convert `SimpleQuery` to `ByteString`.

parseQuery :: ByteString -> Query #

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 `' '`

parseSimpleQuery :: ByteString -> SimpleQuery #

Parse `SimpleQuery` from a `ByteString`.

## Escape only parts

renderQueryPartialEscape #

Arguments

:: Bool | prepend question mark?
-> PartialEscapeQuery |
-> ByteString |

Convert `PartialEscapeQuery` to `ByteString`.

renderQueryBuilderPartialEscape #

Arguments

:: Bool | prepend a question mark?
-> PartialEscapeQuery |
-> Builder |

Convert `PartialEscapeQuery` to a `Builder`.

data EscapeItem #

For some URIs characters must not be URI encoded, e.g. `'+'` or `':'` in `q=a+language:haskell+created:2009-01-01..2009-02-01&sort=stars` The character list unreservedPI instead of unreservedQS would solve this. But we explicitly decide what part to encode. This is mandatory when searching for `'+'`: `q=%2B+language:haskell`.

Constructors

QE ByteString |
QN ByteString |

#### Instances

Instances details

Show EscapeItem # |
Instance details Defined in Network.HTTP.Types.URI Methods showsPrec :: Int -> EscapeItem -> ShowS show :: EscapeItem -> String showList :: [EscapeItem] -> ShowS
Eq EscapeItem # |
Instance details Defined in Network.HTTP.Types.URI Methods (==) :: EscapeItem -> EscapeItem -> Bool (/=) :: EscapeItem -> EscapeItem -> Bool
Ord EscapeItem # |
Instance details Defined in Network.HTTP.Types.URI Methods compare :: EscapeItem -> EscapeItem -> Ordering (<) :: EscapeItem -> EscapeItem -> Bool (<=) :: EscapeItem -> EscapeItem -> Bool (>) :: EscapeItem -> EscapeItem -> Bool (>=) :: EscapeItem -> EscapeItem -> Bool max :: EscapeItem -> EscapeItem -> EscapeItem min :: EscapeItem -> EscapeItem -> EscapeItem

type PartialEscapeQueryItem = (ByteString, [EscapeItem]) #

Query item

type PartialEscapeQuery = [PartialEscapeQueryItem] #

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)] #

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

queryTextToQuery :: QueryText -> Query #

Convert `QueryText` to `Query`.

queryToQueryText :: Query -> QueryText #

Convert `Query` to `QueryText` (leniently decoding the UTF-8).

renderQueryText #

Arguments

:: Bool | prepend a question mark?
-> QueryText |
-> Builder |

Convert `QueryText` to a `Builder`.

parseQueryText :: ByteString -> QueryText #

Parse `QueryText` from a `ByteString`. See `parseQuery` for details.

## Generalized query types

class QueryLike a where #

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 #

Convert to `Query`.

#### Instances

Instances details

(QueryKeyLike k, QueryValueLike v) => QueryLike [Maybe (k, v)] # |
Instance details Defined in Network.HTTP.Types.QueryLike Methods toQuery :: [Maybe (k, v)] -> Query #
(QueryKeyLike k, QueryValueLike v) => QueryLike [(k, v)] # |
Instance details Defined in Network.HTTP.Types.QueryLike Methods toQuery :: [(k, v)] -> Query #

## Path segments

encodePathSegments :: [Text] -> Builder #

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] #

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

encodePathSegmentsRelative :: [Text] -> Builder #

Like encodePathSegments, but without the initial slash.

## Path (segments + query string)

extractPath :: ByteString -> ByteString #

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 #

Encode a whole path (path segments + query).

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

Decode a whole path (path segments + query).

## URL encoding / decoding

urlEncodeBuilder #

Arguments

:: Bool | Whether input is in query string. True: Query string, False: Path element
-> ByteString |
-> Builder |

Percent-encoding for URLs (using `Builder`).

urlEncode #

Arguments

:: Bool | Whether to decode `'+'` to `' '`
-> ByteString | The ByteString to encode as URL
-> ByteString | The encoded URL

Percent-encoding for URLs.

urlDecode #

Arguments

:: Bool | Whether to decode `'+'` to `' '`
-> ByteString |
-> ByteString |

Percent-decoding.