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

Network.HTTP.Types

Contents

Synopsis

Methods

type Method = AsciiSource

HTTP method (flat string type).

methodPost :: MethodSource

HTTP Method constants.

data StdMethod Source

HTTP standard method (as defined by RFC 2616).

Constructors

GET 
POST 
HEAD 
PUT 
DELETE 
TRACE 
CONNECT 
OPTIONS 

parseMethod :: Method -> Either Ascii StdMethodSource

Convert a method ByteString to a StdMethod if possible.

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

Note that the Show instance is only for debugging.

Constructors

Status 

Instances

statusNotAllowed :: StatusSource

Method Not Allowed

statusServerError :: StatusSource

Internal Server Error

Headers

type Header = (CIAscii, Ascii)Source

Header

type RequestHeaders = [Header]Source

Request Headers

type ResponseHeaders = [Header]Source

Response Headers

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

Convert Query to ByteString.

renderQueryBuilderSource

Arguments

:: Bool

prepend a question mark?

-> Query 
-> AsciiBuilder 

renderSimpleQuerySource

Arguments

:: Bool

prepend question mark?

-> SimpleQuery 
-> Ascii 

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)

renderQueryTextSource

Arguments

:: Bool

prepend a question mark?

-> QueryText 
-> AsciiBuilder 

Path segments

encodePathSegments :: [Text] -> AsciiBuilderSource

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

urlEncodeBuilderSource

Arguments

:: Bool

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

-> ByteString 
-> AsciiBuilder 

urlDecodeSource

Arguments

:: Bool

Whether to decode + to ' '

-> ByteString 
-> ByteString 

Percent-decoding.