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

Network.HTTP.Types

Contents

Synopsis

General

Methods

type Method = Ascii

HTTP method (flat string type).

methodPost :: Method

HTTP Method constants.

data StdMethod

HTTP standard method (as defined by RFC 2616).

Constructors

GET 
POST 
HEAD 
PUT 
DELETE 
TRACE 
CONNECT 
OPTIONS 

parseMethod :: Method -> Either Ascii StdMethod

Convert a method ByteString to a StdMethod if possible.

renderMethod :: Either Ascii 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
 

http09 :: HttpVersion

HTTP 0.9

http10 :: HttpVersion

HTTP 1.0

http11 :: HttpVersion

HTTP 1.1

Status

data Status

HTTP Status.

Only the statusCode is used for comparisons.

Note that the Show instance is only for debugging.

Constructors

Status 

Instances

statusPartialContent :: Status

PartialContent

statusMovedPermanently :: Status

Moved Permanently

statusSeeOther :: Status

See Other

statusNotModified :: Status

Not Modified

statusBadRequest :: Status

Bad Request

statusUnauthorized :: Status

Unauthorized

statusForbidden :: Status

Forbidden

statusNotFound :: Status

Not Found

statusNotAllowed :: Status

Method Not Allowed

statusPreconditionFailed :: Status

Precondition Failed

statusRequestedRangeNotSatisfiable :: Status

Requested Range Not Satisfiable

statusServerError :: Status

Internal Server Error

statusNotImplemented :: Status

Not Implemented

Headers

type Header = (CI Ascii, Ascii)

Header

type RequestHeaders = [Header]

Request Headers

type ResponseHeaders = [Header]

Response Headers

headerAuthorization :: Ascii -> Header

HTTP Headers

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.

renderQuery

Arguments

:: Bool

prepend question mark?

-> Query 
-> Ascii 

Convert Query to ByteString.

renderQueryBuilder

Arguments

:: Bool

prepend a question mark?

-> Query 
-> Builder 

renderSimpleQuery

Arguments

:: Bool

prepend question mark?

-> SimpleQuery 
-> Ascii 

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.

parseSimpleQuery :: ByteString -> SimpleQuery

Parse SimpleQuery from a ByteString.

Text query string (UTF8 encoded)

type QueryText = [(Text, Maybe Text)]

renderQueryText

Arguments

:: Bool

prepend a question mark?

-> QueryText 
-> Builder 

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 :@=+$,
  • Intercalates with a slash.

For example:

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

"foo/bar/baz"

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

"foo%20bar/baz%2Fbin"

 encodePathInfo [\"\"]

"%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.

Path (segments + query string)

URL encoding / decoding

urlEncodeBuilder

Arguments

:: Bool

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

-> ByteString 
-> Builder 

urlDecode

Arguments

:: Bool

Whether to decode + to ' '

-> ByteString 
-> ByteString 

Percent-decoding.