salvia-protocol-1.0.1: Salvia webserver protocol suite supporting URI, HTTP, Cookie and MIME.

Network.Protocol.Http

Contents

Synopsis

HTTP message data types.

data Method Source

List of HTTP request methods.

Instances

data Version Source

HTTP protocol version.

newtype Headers Source

HTTP headers as mapping from keys to values.

Constructors

Headers 

Fields

unHeaders :: [(Key, Value)]
 

Instances

data Request Source

Request specific part of HTTP messages.

Constructors

Request Method String 

Instances

data Response Source

Response specific part of HTTP messages.

Constructors

Response Status 

Instances

data Http a Source

An HTTP message. The message body is *not* included.

Constructors

Http a Version Headers 

Instances

Creating (parts of) messages.

http10 :: VersionSource

Create HTTP 1.0 version.

http11 :: VersionSource

Create HTTP 1.1 version.

emptyHeaders :: HeadersSource

Create an empty set of headers.

emptyRequest :: Http RequestSource

Create an empty HTTP request message.

emptyResponse :: Http ResponseSource

Create an empty HTTP response message.

Accessing fields.

methods :: [Method]Source

All recognized method constructors as a list.

major :: Version :-> IntSource

Label to access the major part of the version.

minor :: Version :-> IntSource

Label to access the minor part of the version.

headers :: Http a :-> HeadersSource

Label to access the header of an HTTP message.

version :: Http a :-> VersionSource

Label to access the version part of an HTTP message.

headline :: Http a :-> aSource

Label to access the header line part of an HTTP message.

method :: Http Request :-> MethodSource

Label to access the method part of an HTTP request message.

uri :: Http Request :-> StringSource

Label to access the URI part of an HTTP request message.

asUri :: Http Request :-> UriSource

Label to access the URI part of an HTTP request message and access it as a true URI data type.

status :: Http Response :-> StatusSource

Label to access the status part of an HTTP response message.

normalizeHeader :: Key -> KeySource

Normalize the capitalization of an HTTP header key.

header :: Key -> Http a :-> Maybe ValueSource

Generic label to access an HTTP header field by key.

Accessing specific header fields.

contentLength :: (Read i, Integral i) => Http a :-> Maybe iSource

Access the Content-Length header field.

connection :: Http a :-> Maybe StringSource

Access the Connection header field.

accept :: Http a :-> Maybe ParametersSource

Access the Accept header field.

acceptEncoding :: Http a :-> Maybe [String]Source

Access the Accept-Encoding header field.

acceptLanguage :: Http a :-> Maybe [String]Source

Access the Accept-Language header field.

cacheControl :: Http a :-> Maybe StringSource

Access the Connection header field.

keepAlive :: (Read i, Integral i) => Http a :-> Maybe iSource

Access the Keep-Alive header field.

cookie :: Http Request :-> Maybe StringSource

Access the Cookie header field.

setCookie :: Http Response :-> Maybe StringSource

Access the Set-Cookie header field.

location :: Http a :-> Maybe StringSource

Access the Location header field.

contentType :: Http a :-> Maybe (String, Maybe String)Source

Access the Content-Type header field. The content-type will be parsed into a mimetype and optional charset.

date :: Http a :-> Maybe StringSource

Access the Date header field.

hostname :: Http a :-> Maybe StringSource

Access the Host header field.

server :: Http a :-> Maybe StringSource

Access the Server header field.

userAgent :: Http a :-> Maybe StringSource

Access the User-Agent header field.

upgrade :: Http a :-> Maybe StringSource

Access the Upgrade header field.

lastModified :: Http a :-> Maybe ValueSource

Access the Last-Modified header field.

acceptRanges :: Http a :-> Maybe ValueSource

Access the Accept-Ranges header field.

eTag :: Http a :-> Maybe ValueSource

Access the ETag header field.

Parsing HTTP messages.

parseRequest :: String -> Either String (Http Request)Source

Parse a string as an HTTP request message. This parser is very forgiving.

parseResponse :: String -> Either String (Http Response)Source

Parse a string as an HTTP request message. This parser is very forgiving.

parseHeaders :: String -> Either String HeadersSource

Parse a string as a list of HTTP headers.

Exposure of internal parsec parsers.

pRequest :: GenParser Char st (Http Request)Source

Parsec parser to parse the header part of an HTTP request.

pResponse :: GenParser Char st (Http Response)Source

Parsec parser to parse the header part of an HTTP response.

pHeaders :: GenParser Char st HeadersSource

Parsec parser to parse one or more, possibly multiline, HTTP header lines.

pVersion :: GenParser Char st VersionSource

Parsec parser to parse HTTP versions. Recognizes X.X versions only.

pMethod :: GenParser Char st MethodSource

Parsec parser to parse an HTTP method. Parses arbitrary method but actually recognizes the ones listed as a constructor for Method.

Parser helper methods.

versionFromString :: String -> VersionSource

Recognizes HTTP protocol version 1.0 and 1.1, all other string will produce version 1.1.

methodFromString :: String -> MethodSource

Helper to turn fully capitalized string into request method.

Printer helper methods.

showRequestLine :: Http Request -> String -> StringSource

Show HTTP request status line.

showResponseLine :: Http Response -> String -> StringSource

Show HTTP response status line.

Handling HTTP status codes.

statusFailure :: Status -> BoolSource

Every status greater-than or equal to 400 is considered to be a failure.

statusFromCode :: Int -> StatusSource

Conversion from status numbers to codes.

codeFromStatus :: Status -> IntSource

Conversion from status codes to numbers.