http-types-0.8.4: Generic HTTP types for Haskell (for both client and server code).

Safe HaskellNone

Network.HTTP.Types

Contents

Synopsis

Methods

type Method = ByteStringSource

HTTP method (flat string type).

methodGet :: MethodSource

HTTP Method constants.

methodPost :: MethodSource

HTTP Method constants.

methodHead :: MethodSource

HTTP Method constants.

methodPut :: MethodSource

HTTP Method constants.

methodDelete :: MethodSource

HTTP Method constants.

methodTrace :: MethodSource

HTTP Method constants.

methodConnect :: MethodSource

HTTP Method constants.

methodOptions :: MethodSource

HTTP Method constants.

methodPatch :: MethodSource

HTTP Method constants.

data StdMethod Source

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 

parseMethod :: Method -> Either ByteString StdMethodSource

Convert a method ByteString to a StdMethod if possible.

renderMethod :: Either ByteString StdMethod -> MethodSource

Convert an algebraic method to a ByteString.

renderStdMethod :: StdMethod -> MethodSource

Convert a StdMethod to a ByteString.

Versions

data HttpVersion Source

HTTP Version.

Note that the Show instance is intended merely for debugging.

Constructors

HttpVersion 

Fields

httpMajor :: !Int
 
httpMinor :: !Int
 

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.

Constructors

Status 

mkStatus :: Int -> ByteString -> StatusSource

Create a Status from status code and message.

status100 :: StatusSource

Continue 100

continue100 :: StatusSource

Continue 100

status101 :: StatusSource

Switching Protocols 101

switchingProtocols101 :: StatusSource

Switching Protocols 101

status201 :: StatusSource

Created 201

created201 :: StatusSource

Created 201

status202 :: StatusSource

Accepted 202

accepted202 :: StatusSource

Accepted 202

status203 :: StatusSource

Non-Authoritative Information 203

nonAuthoritative203 :: StatusSource

Non-Authoritative Information 203

status204 :: StatusSource

No Content 204

noContent204 :: StatusSource

No Content 204

status205 :: StatusSource

Reset Content 205

resetContent205 :: StatusSource

Reset Content 205

status206 :: StatusSource

Partial Content 206

partialContent206 :: StatusSource

Partial Content 206

status300 :: StatusSource

Multiple Choices 300

multipleChoices300 :: StatusSource

Multiple Choices 300

status301 :: StatusSource

Moved Permanently 301

movedPermanently301 :: StatusSource

Moved Permanently 301

status302 :: StatusSource

Found 302

found302 :: StatusSource

Found 302

status303 :: StatusSource

See Other 303

seeOther303 :: StatusSource

See Other 303

status304 :: StatusSource

Not Modified 304

notModified304 :: StatusSource

Not Modified 304

status305 :: StatusSource

Use Proxy 305

useProxy305 :: StatusSource

Use Proxy 305

status307 :: StatusSource

Temporary Redirect 307

temporaryRedirect307 :: StatusSource

Temporary Redirect 307

status400 :: StatusSource

Bad Request 400

badRequest400 :: StatusSource

Bad Request 400

status401 :: StatusSource

Unauthorized 401

unauthorized401 :: StatusSource

Unauthorized 401

status402 :: StatusSource

Payment Required 402

paymentRequired402 :: StatusSource

Payment Required 402

status403 :: StatusSource

Forbidden 403

forbidden403 :: StatusSource

Forbidden 403

status404 :: StatusSource

Not Found 404

notFound404 :: StatusSource

Not Found 404

status405 :: StatusSource

Method Not Allowed 405

methodNotAllowed405 :: StatusSource

Method Not Allowed 405

status406 :: StatusSource

Not Acceptable 406

notAcceptable406 :: StatusSource

Not Acceptable 406

status407 :: StatusSource

Proxy Authentication Required 407

proxyAuthenticationRequired407 :: StatusSource

Proxy Authentication Required 407

status408 :: StatusSource

Request Timeout 408

requestTimeout408 :: StatusSource

Request Timeout 408

status409 :: StatusSource

Conflict 409

conflict409 :: StatusSource

Conflict 409

gone410 :: StatusSource

Gone 410

status411 :: StatusSource

Length Required 411

lengthRequired411 :: StatusSource

Length Required 411

status412 :: StatusSource

Precondition Failed 412

preconditionFailed412 :: StatusSource

Precondition Failed 412

status413 :: StatusSource

Request Entity Too Large 413

requestEntityTooLarge413 :: StatusSource

Request Entity Too Large 413

status414 :: StatusSource

Request-URI Too Long 414

requestURITooLong414 :: StatusSource

Request-URI Too Long 414

status415 :: StatusSource

Unsupported Media Type 415

unsupportedMediaType415 :: StatusSource

Unsupported Media Type 415

status416 :: StatusSource

Requested Range Not Satisfiable 416

requestedRangeNotSatisfiable416 :: StatusSource

Requested Range Not Satisfiable 416

status417 :: StatusSource

Expectation Failed 417

expectationFailed417 :: StatusSource

Expectation Failed 417

status418 :: StatusSource

I'm a teapot 418

imATeaPot418 :: StatusSource

I'm a teapot 418

status500 :: StatusSource

Internal Server Error 500

internalServerError500 :: StatusSource

Internal Server Error 500

status501 :: StatusSource

Not Implemented 501

notImplemented501 :: StatusSource

Not Implemented 501

status502 :: StatusSource

Bad Gateway 502

badGateway502 :: StatusSource

Bad Gateway 502

status503 :: StatusSource

Service Unavailable 503

serviceUnavailable503 :: StatusSource

Service Unavailable 503

status504 :: StatusSource

Gateway Timeout 504

gatewayTimeout504 :: StatusSource

Gateway Timeout 504

status505 :: StatusSource

HTTP Version Not Supported 505

httpVersionNotSupported505 :: StatusSource

HTTP Version Not Supported 505

statusIsInformational :: Status -> BoolSource

Informational class

statusIsSuccessful :: Status -> BoolSource

Successful class

statusIsRedirection :: Status -> BoolSource

Redirection class

statusIsClientError :: Status -> BoolSource

Client Error class

statusIsServerError :: Status -> BoolSource

Server Error class

Headers

Types

type HeaderName = CI ByteStringSource

Header name

type RequestHeaders = [Header]Source

Request Headers

type ResponseHeaders = [Header]Source

Response Headers

Common headers

hAccept :: HeaderNameSource

HTTP Header names

hAcceptLanguage :: HeaderNameSource

HTTP Header names

hAuthorization :: HeaderNameSource

HTTP Header names

hCacheControl :: HeaderNameSource

HTTP Header names

hCookie :: HeaderNameSource

HTTP Header names

hConnection :: HeaderNameSource

HTTP Header names

hContentEncoding :: HeaderNameSource

HTTP Header names

hContentLength :: HeaderNameSource

HTTP Header names

hContentMD5 :: HeaderNameSource

HTTP Header names

hContentType :: HeaderNameSource

HTTP Header names

hDate :: HeaderNameSource

HTTP Header names

hIfModifiedSince :: HeaderNameSource

HTTP Header names

hIfRange :: HeaderNameSource

HTTP Header names

hLastModified :: HeaderNameSource

HTTP Header names

hLocation :: HeaderNameSource

HTTP Header names

hRange :: HeaderNameSource

HTTP Header names

hReferer :: HeaderNameSource

HTTP Header names

hServer :: HeaderNameSource

HTTP Header names

hUserAgent :: HeaderNameSource

HTTP Header names

Byte ranges

data ByteRange Source

RFC 2616 Byte range (individual).

Negative indices are not allowed!

type ByteRanges = [ByteRange]Source

RFC 2616 Byte ranges (set).

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.

renderQuerySource

Arguments

:: Bool

prepend question mark?

-> Query 
-> ByteString 

Convert Query to ByteString.

renderQueryBuilderSource

Arguments

:: Bool

prepend a question mark?

-> Query 
-> Builder 

Convert Query to a Builder.

renderSimpleQuerySource

Arguments

:: Bool

prepend question mark?

-> SimpleQuery 
-> ByteString 

Convert SimpleQuery to ByteString.

parseQuery :: ByteString -> QuerySource

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.

Text query string (UTF8 encoded)

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

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

queryToQueryText :: Query -> QueryTextSource

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

renderQueryTextSource

Arguments

:: Bool

prepend a question mark?

-> QueryText 
-> Builder 

Convert QueryText to a Builder.

Generalized query types

class QueryLike a whereSource

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 -> QuerySource

Convert to Query.

Instances

Path segments

encodePathSegments :: [Text] -> BuilderSource

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

Like encodePathSegments, but without the initial slash.

Path (segments + query string)

encodePath :: [Text] -> Query -> BuilderSource

Encode a whole path (path segments + query).

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

Decode a whole path (path segments + query).

URL encoding / decoding

urlEncodeBuilderSource

Arguments

:: Bool

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

-> ByteString 
-> Builder 

Percent-encoding for URLs (using Builder).

urlEncode :: Bool -> ByteString -> ByteStringSource

Percent-encoding for URLs.

urlDecodeSource

Arguments

:: Bool

Whether to decode + to ' '

-> ByteString 
-> ByteString 

Percent-decoding.