Safe Haskell | None |
---|---|
Language | Haskell98 |
- type Method = ByteString
- methodGet :: Method
- methodPost :: Method
- methodHead :: Method
- methodPut :: Method
- methodDelete :: Method
- methodTrace :: Method
- methodConnect :: Method
- methodOptions :: Method
- methodPatch :: Method
- data StdMethod
- parseMethod :: Method -> Either ByteString StdMethod
- renderMethod :: Either ByteString StdMethod -> Method
- renderStdMethod :: StdMethod -> Method
- data HttpVersion = HttpVersion {}
- http09 :: HttpVersion
- http10 :: HttpVersion
- http11 :: HttpVersion
- data Status = Status {}
- 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
- 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
- status500 :: Status
- internalServerError500 :: Status
- status501 :: Status
- notImplemented501 :: Status
- status502 :: Status
- badGateway502 :: Status
- status503 :: Status
- serviceUnavailable503 :: Status
- status504 :: Status
- gatewayTimeout504 :: Status
- status505 :: Status
- httpVersionNotSupported505 :: 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
- renderByteRangeBuilder :: ByteRange -> Builder
- renderByteRange :: ByteRange -> ByteString
- type ByteRanges = [ByteRange]
- renderByteRangesBuilder :: ByteRanges -> Builder
- renderByteRanges :: ByteRanges -> ByteString
- 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
- type QueryText = [(Text, Maybe Text)]
- queryTextToQuery :: QueryText -> Query
- queryToQueryText :: Query -> QueryText
- renderQueryText :: Bool -> QueryText -> Builder
- parseQueryText :: ByteString -> QueryText
- class QueryLike a where
- 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 Source
HTTP method (flat string type).
HTTP Method constants.
HTTP Method constants.
HTTP Method constants.
HTTP Method constants.
methodConnect :: Method Source
HTTP Method constants.
methodOptions :: Method Source
HTTP Method constants.
HTTP Method constants.
HTTP standard method (as defined by RFC 2616, and PATCH which is defined by RFC 5789).
parseMethod :: Method -> Either ByteString StdMethod Source
Convert a method ByteString
to a StdMethod
if possible.
renderMethod :: Either ByteString StdMethod -> Method Source
Convert an algebraic method to a ByteString
.
renderStdMethod :: StdMethod -> Method Source
Convert a StdMethod
to a ByteString
.
Versions
data HttpVersion Source
HTTP Version.
Note that the Show instance is intended merely for debugging.
HTTP 0.9
HTTP 1.0
HTTP 1.1
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.
mkStatus :: Int -> ByteString -> Status Source
Create a Status from status code and message.
Continue 100
switchingProtocols101 :: Status Source
Switching Protocols 101
Created 201
Accepted 202
nonAuthoritative203 :: Status Source
Non-Authoritative Information 203
No Content 204
resetContent205 :: Status Source
Reset Content 205
partialContent206 :: Status Source
Partial Content 206
multipleChoices300 :: Status Source
Multiple Choices 300
movedPermanently301 :: Status Source
Moved Permanently 301
See Other 303
notModified304 :: Status Source
Not Modified 304
Use Proxy 305
temporaryRedirect307 :: Status Source
Temporary Redirect 307
badRequest400 :: Status Source
Bad Request 400
unauthorized401 :: Status Source
Unauthorized 401
paymentRequired402 :: Status Source
Payment Required 402
Forbidden 403
Not Found 404
methodNotAllowed405 :: Status Source
Method Not Allowed 405
notAcceptable406 :: Status Source
Not Acceptable 406
proxyAuthenticationRequired407 :: Status Source
Proxy Authentication Required 407
requestTimeout408 :: Status Source
Request Timeout 408
Conflict 409
lengthRequired411 :: Status Source
Length Required 411
preconditionFailed412 :: Status Source
Precondition Failed 412
requestEntityTooLarge413 :: Status Source
Request Entity Too Large 413
requestURITooLong414 :: Status Source
Request-URI Too Long 414
unsupportedMediaType415 :: Status Source
Unsupported Media Type 415
requestedRangeNotSatisfiable416 :: Status Source
Requested Range Not Satisfiable 416
expectationFailed417 :: Status Source
Expectation Failed 417
I'm a teapot 418
internalServerError500 :: Status Source
Internal Server Error 500
notImplemented501 :: Status Source
Not Implemented 501
badGateway502 :: Status Source
Bad Gateway 502
serviceUnavailable503 :: Status Source
Service Unavailable 503
gatewayTimeout504 :: Status Source
Gateway Timeout 504
httpVersionNotSupported505 :: Status Source
HTTP Version Not Supported 505
statusIsInformational :: Status -> Bool Source
Informational class
statusIsSuccessful :: Status -> Bool Source
Successful class
statusIsRedirection :: Status -> Bool Source
Redirection class
statusIsClientError :: Status -> Bool Source
Client Error class
statusIsServerError :: Status -> Bool Source
Server Error class
Headers
Types
type Header = (HeaderName, ByteString) Source
Header
type HeaderName = CI ByteString Source
Header name
type RequestHeaders = [Header] Source
Request Headers
type ResponseHeaders = [Header] Source
Response Headers
Common headers
HTTP Header names According to http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html
hAcceptLanguage :: HeaderName Source
HTTP Header names According to http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html
hAuthorization :: HeaderName Source
HTTP Header names According to http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html
hCacheControl :: HeaderName Source
HTTP Header names According to http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html
HTTP Header names According to http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html
hConnection :: HeaderName Source
HTTP Header names According to http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html
hContentEncoding :: HeaderName Source
HTTP Header names According to http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html
hContentLength :: HeaderName Source
HTTP Header names According to http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html
hContentMD5 :: HeaderName Source
HTTP Header names According to http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html
hContentType :: HeaderName Source
HTTP Header names According to http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html
HTTP Header names According to http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html
hIfModifiedSince :: HeaderName Source
HTTP Header names According to http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html
HTTP Header names According to http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html
hLastModified :: HeaderName Source
HTTP Header names According to http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html
hLocation :: HeaderName Source
HTTP Header names According to http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html
HTTP Header names According to http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html
HTTP Header names According to http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html
HTTP Header names According to http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html
hUserAgent :: HeaderName Source
HTTP Header names According to http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html
Byte ranges
RFC 2616 Byte range (individual).
Negative indices are not allowed!
type ByteRanges = [ByteRange] Source
RFC 2616 Byte ranges (set).
URI
Query string
type QueryItem = (ByteString, Maybe ByteString) Source
Query item
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.
simpleQueryToQuery :: SimpleQuery -> Query Source
Convert SimpleQuery
to Query
.
Convert Query
to a Builder
.
:: Bool | prepend question mark? |
-> SimpleQuery | |
-> ByteString |
Convert SimpleQuery
to ByteString
.
parseQuery :: ByteString -> Query Source
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 Source
Parse SimpleQuery
from a ByteString
.
Text query string (UTF8 encoded)
type QueryText = [(Text, Maybe Text)] Source
Like Query, but with Text
instead of ByteString
(UTF8-encoded).
queryToQueryText :: Query -> QueryText Source
parseQueryText :: ByteString -> QueryText Source
Parse QueryText
from a ByteString
. See parseQuery
for details.
Generalized query types
class QueryLike a where Source
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.
(QueryKeyLike k, QueryValueLike v) => QueryLike [(k, v)] Source | |
(QueryKeyLike k, QueryValueLike v) => QueryLike [Maybe (k, v)] Source |
Path segments
encodePathSegments :: [Text] -> Builder Source
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] -> Builder Source
Like encodePathSegments, but without the initial slash.
Path (segments + query string)
extractPath :: ByteString -> ByteString Source
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 Source
Encode a whole path (path segments + query).
decodePath :: ByteString -> ([Text], Query) Source
Decode a whole path (path segments + query).
URL encoding / decoding
:: Bool | Whether input is in query string. True: Query string, False: Path element |
-> ByteString | |
-> Builder |
Percent-encoding for URLs (using Builder
).
:: Bool | Whether to decode |
-> ByteString | The ByteString to encode as URL |
-> ByteString | The encoded URL |
Percent-encoding for URLs.