HORIZON HASKELLDocslts/ghc-9.10.x248f8f02026-10-05Search names, modules, packages, or :: a typeCtrl K

GHC 9.10.3 · lts/ghc-9.10.x · 248f8f0 · 2026-10-05

Modulehttp-types-0.12.4Haskell2010

Network.HTTP.Types

  • 18 types
  • 1 class
  • 162 values
  • Packagehttp-types-0.12.4
  • Exports181
  • LanguageHaskell2010
  • LicenceBSD-3-Clause
  • SourceMethod.hs

Methods

1 declaration

For more information: Network.HTTP.Types.Method

Constants

datadata StdMethod
#

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

Instances10Bounded, Enum, Eq, Data, Ord, Read, …

Parsing and redering methods

Versions

5 declarations

For more information: Network.HTTP.Types.Version

datadata HttpVersion
#

HTTP Version.

Note that the Show instance is intended merely for debugging.

Instances6Eq, Data, Ord, Show, Generic, Rep

Status

1 declaration

For more information: Network.HTTP.Types.Status

datadata 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.

Instances8Bounded, Enum, Eq, Data, Ord, Show, …

Constants

Headers

0 declarations

For more information: Network.HTTP.Types.Header

Types

typetype Header = (HeaderName, ByteString)
#

A full HTTP header field with the name and value separated.

E.g. "Content-Length: 28" parsed into a Header would turn into ("Content-Length", "28")

typetype HeaderName = CI ByteString
#

A case-insensitive name of a header field.

This is the part of the header field before the colon: HeaderName: some value

Common headers

Byte ranges

datadata ByteRange
#

An individual byte range.

Negative indices are not allowed!

Instances6Eq, Data, Ord, Show, Generic, Rep

Parse the value of a Range header into a ByteRanges.

Example8 expressions
parseByteRanges "error"NothingparseByteRanges "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

0 declarations

For more extensive information: Network.HTTP.Types.URI

Query strings

Query

valueparseQuery :: 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 ' '

Text query string (UTF8 encoded)

SimpleQuery

PartialEscapeQuery

datadata EscapeItem
#

Section of a query item value that decides whether to use regular URL encoding (using 'urlEncode True') with QE, or to not encode anything with QN.

Constructors

Instances3Eq, Ord, Show
  • Eq EscapeItemDefined in http-types-0.12.4 · Network.HTTP.Types.URI
  • Ord EscapeItemDefined in http-types-0.12.4 · Network.HTTP.Types.URI
  • Show EscapeItemDefined in http-types-0.12.4 · Network.HTTP.Types.URI

Generalized query types

classclass 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

Instances2QueryLike

Path

Segments + Query String

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

Though a more accurate description of this function's behaviour is that it removes the domain/origin if the string starts with an HTTP protocol. (i.e. http:// or https://)

This function will not change anything when given any other ByteString. (except return a root path "/" if given an empty string)

Example1 expression
extractPath "/path""/path"
Example1 expression
extractPath "http://example.com:8080/path""/path"
Example1 expression
extractPath "http://example.com""/"
Example1 expression
extractPath """/"
Example1 expression
extractPath "www.google.com/some/path""www.google.com/some/path"

Path Segments

valueencodePathSegments :: [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.

  • Prepends each segment with a slash.

  • Performs percent-encoding on all characters that are not:

    • alphanumeric (i.e. A-Z and a-z)

    • digits (i.e. 0-9)

    • a dash '-', an underscore '_', a dot '.', or a tilde '~'

For example:

Example1 expression
encodePathSegments ["foo", "bar1", "~baz"]"/foo/bar1/~baz"
Example1 expression
encodePathSegments ["foo bar", "baz/bin"]"/foo%20bar/baz%2Fbin"
Example1 expression
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.

URL encoding / decoding

Percent-encoding for URLs.

In short:

  • if you're encoding (parts of) a path element, use False.

  • if you're encoding (parts of) a query string, use True.

In-depth explanation

This will substitute every byte with its percent-encoded equivalent unless:

  • The byte is alphanumeric. (i.e. A-Z, a-z, or 0-9)

  • The byte is either a dash '-', an underscore '_', a dot '.', or a tilde '~'

  • If False is used, the following will also not be percent-encoded:

    • colon ':', at sign '@', ampersand '&', equals sign '=', plus sign '+', dollar sign '$' or a comma ','