Network.HTTP.Types.Header

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

Safe Haskell | Safe-Inferred
Language | Haskell2010

Network.HTTP.Types.Header

Contents

- HTTP Headers
  - Common headers
  - Byte ranges

Description

Type and constants for handling HTTP header fields.

At the bottom are also some functions to handle certain header field values.

Synopsis

- type Header = (HeaderName, ByteString)
- type HeaderName = CI ByteString
- type RequestHeaders = [Header]
- type ResponseHeaders = [Header]
- hAccept :: HeaderName
- hAcceptCharset :: HeaderName
- hAcceptEncoding :: HeaderName
- hAcceptLanguage :: HeaderName
- hAcceptRanges :: HeaderName
- hAge :: HeaderName
- hAllow :: HeaderName
- hAuthorization :: HeaderName
- hCacheControl :: HeaderName
- hConnection :: HeaderName
- hContentDisposition :: HeaderName
- hContentEncoding :: HeaderName
- hContentLanguage :: HeaderName
- hContentLength :: HeaderName
- hContentLocation :: HeaderName
- hContentMD5 :: HeaderName
- hContentRange :: HeaderName
- hContentType :: HeaderName
- hCookie :: HeaderName
- hDate :: HeaderName
- hETag :: HeaderName
- hExpect :: HeaderName
- hExpires :: HeaderName
- hFrom :: HeaderName
- hHost :: HeaderName
- hIfMatch :: HeaderName
- hIfModifiedSince :: HeaderName
- hIfNoneMatch :: HeaderName
- hIfRange :: HeaderName
- hIfUnmodifiedSince :: HeaderName
- hLastModified :: HeaderName
- hLocation :: HeaderName
- hMaxForwards :: HeaderName
- hMIMEVersion :: HeaderName
- hOrigin :: HeaderName
- hPragma :: HeaderName
- hPrefer :: HeaderName
- hPreferenceApplied :: HeaderName
- hProxyAuthenticate :: HeaderName
- hProxyAuthorization :: HeaderName
- hRange :: HeaderName
- hReferer :: HeaderName
- hRetryAfter :: HeaderName
- hServer :: HeaderName
- hSetCookie :: HeaderName
- hTE :: HeaderName
- hTrailer :: HeaderName
- hTransferEncoding :: HeaderName
- hUpgrade :: HeaderName
- hUserAgent :: HeaderName
- hVary :: HeaderName
- hVia :: HeaderName
- hWWWAuthenticate :: HeaderName
- hWarning :: HeaderName
- data ByteRange
  - = ByteRangeFrom !Integer
  - | ByteRangeFromTo !Integer !Integer
  - | ByteRangeSuffix !Integer
- renderByteRangeBuilder :: ByteRange -> Builder
- renderByteRange :: ByteRange -> ByteString
- type ByteRanges = [ByteRange]
- renderByteRangesBuilder :: ByteRanges -> Builder
- renderByteRanges :: ByteRanges -> ByteString
- parseByteRanges :: ByteString -> Maybe ByteRanges

# HTTP Headers

type 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")`

type 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`

type RequestHeaders = [Header] #

A list of `Header`s.

Same type as `ResponseHeaders`, but useful to differentiate in type signatures.

type ResponseHeaders = [Header] #

A list of `Header`s.

Same type as `RequestHeaders`, but useful to differentiate in type signatures.

## Common headers

The following header constants are provided for convenience, to prevent accidental spelling errors.

hAccept :: HeaderName #

Accept

Since: 0.7.0

hAcceptCharset :: HeaderName #

Accept-Charset

Since: 0.9

hAcceptEncoding :: HeaderName #

Accept-Encoding

Since: 0.9

hAcceptLanguage :: HeaderName #

Accept-Language

Since: 0.7.0

hAcceptRanges :: HeaderName #

Accept-Ranges

Since: 0.9

hAge :: HeaderName #

Age

Since: 0.9

hAllow :: HeaderName #

Allow

Since: 0.9

hAuthorization :: HeaderName #

Authorization

Since: 0.7.0

hCacheControl :: HeaderName #

Cache-Control

Since: 0.7.0

hConnection :: HeaderName #

Connection

Since: 0.7.0

hContentDisposition :: HeaderName #

Content-Disposition

Since: 0.10

hContentEncoding :: HeaderName #

Content-Encoding

Since: 0.7.0

hContentLanguage :: HeaderName #

Content-Language

Since: 0.9

hContentLength :: HeaderName #

Content-Length

Since: 0.7.0

hContentLocation :: HeaderName #

Content-Location

Since: 0.9

hContentMD5 :: HeaderName #

Content-MD5

This header has been obsoleted in RFC 9110.

Since: 0.7.0

hContentRange :: HeaderName #

Content-Range

Since: 0.9

hContentType :: HeaderName #

Content-Type

Since: 0.7.0

hCookie :: HeaderName #

Cookie

Since: 0.7.0

hDate :: HeaderName #

Date

Since: 0.7.0

hETag :: HeaderName #

ETag

Since: 0.9

hExpect :: HeaderName #

Expect

Since: 0.9

hExpires :: HeaderName #

Expires

Since: 0.9

hFrom :: HeaderName #

From

Since: 0.9

hHost :: HeaderName #

Host

Since: 0.9

hIfMatch :: HeaderName #

If-Match

Since: 0.9

hIfModifiedSince :: HeaderName #

If-Modified-Since

Since: 0.7.0

hIfNoneMatch :: HeaderName #

If-None-Match

Since: 0.9

hIfRange :: HeaderName #

If-Range

Since: 0.7.0

hIfUnmodifiedSince :: HeaderName #

If-Unmodified-Since

Since: 0.9

hLastModified :: HeaderName #

Last-Modified

Since: 0.7.0

hLocation :: HeaderName #

Location

Since: 0.7.1

hMaxForwards :: HeaderName #

Max-Forwards

Since: 0.9

hMIMEVersion :: HeaderName #

MIME-Version

Since: 0.10

hOrigin :: HeaderName #

Origin

Since: 0.10

hPragma :: HeaderName #

Pragma

This header has been deprecated in RFC 9111 in favor of "Cache-Control".

Since: 0.9

hPrefer :: HeaderName #

Prefer

Since: 0.12.2

hPreferenceApplied :: HeaderName #

Preference-Applied

Since: 0.12.2

hProxyAuthenticate :: HeaderName #

Proxy-Authenticate

Since: 0.9

hProxyAuthorization :: HeaderName #

Proxy-Authorization

Since: 0.9

hRange :: HeaderName #

Range

Since: 0.7.0

hReferer :: HeaderName #

Referer

Since: 0.7.0

hRetryAfter :: HeaderName #

Retry-After

Since: 0.9

hServer :: HeaderName #

Server

Since: 0.7.1

hSetCookie :: HeaderName #

Set-Cookie

Since: 0.10

hTE :: HeaderName #

TE

Since: 0.9

hTrailer :: HeaderName #

Trailer

Since: 0.9

hTransferEncoding :: HeaderName #

Transfer-Encoding

Since: 0.9

hUpgrade :: HeaderName #

Upgrade

Since: 0.9

hUserAgent :: HeaderName #

User-Agent

Since: 0.7.0

hVary :: HeaderName #

Vary

Since: 0.9

hVia :: HeaderName #

Via

Since: 0.9

hWWWAuthenticate :: HeaderName #

WWW-Authenticate

Since: 0.9

hWarning :: HeaderName #

Warning

This header has been obsoleted in RFC 9110.

Since: 0.9

## Byte ranges

Convenience functions and types to handle values from Range headers.

https://www.rfc-editor.org/rfc/rfc9110.html#name-byte-ranges

data ByteRange #

An individual byte range.

Negative indices are not allowed!

Since: 0.6.11

Constructors

ByteRangeFrom !Integer |
ByteRangeFromTo !Integer !Integer |
ByteRangeSuffix !Integer |

#### Instances

Instances details

Data ByteRange # | Since: 0.8.4
Instance details Defined in Network.HTTP.Types.Header Methods gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> ByteRange -> c ByteRange # gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c ByteRange # toConstr :: ByteRange -> Constr # dataTypeOf :: ByteRange -> DataType # dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c ByteRange) # dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c ByteRange) # gmapT :: (forall b. Data b => b -> b) -> ByteRange -> ByteRange # gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> ByteRange -> r # gmapQr :: forall r r'. (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> ByteRange -> r # gmapQ :: (forall d. Data d => d -> u) -> ByteRange -> [u] # gmapQi :: Int -> (forall d. Data d => d -> u) -> ByteRange -> u # gmapM :: Monad m => (forall d. Data d => d -> m d) -> ByteRange -> m ByteRange # gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> ByteRange -> m ByteRange # gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> ByteRange -> m ByteRange #
Generic ByteRange # |
Instance details Defined in Network.HTTP.Types.Header Associated Types
type Rep ByteRange | Since: http-types-0.12.4
Instance details Defined in Network.HTTP.Types.Header type Rep ByteRange = D1 ('MetaData "ByteRange" "Network.HTTP.Types.Header" "http-types-0.12.4-HhEPaOzd8crnbrvqiOppv" 'False) (C1 ('MetaCons "ByteRangeFrom" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Integer)) :+: (C1 ('MetaCons "ByteRangeFromTo" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Integer) :*: S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Integer)) :+: C1 ('MetaCons "ByteRangeSuffix" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Integer))))
Methods from :: ByteRange -> Rep ByteRange x # to :: Rep ByteRange x -> ByteRange #
Show ByteRange # | Since: 0.8.4
Instance details Defined in Network.HTTP.Types.Header Methods showsPrec :: Int -> ByteRange -> ShowS # show :: ByteRange -> String # showList :: [ByteRange] -> ShowS #
Eq ByteRange # | Since: 0.8.4
Instance details Defined in Network.HTTP.Types.Header Methods (==) :: ByteRange -> ByteRange -> Bool # (/=) :: ByteRange -> ByteRange -> Bool #
Ord ByteRange # | Since: 0.8.4
Instance details Defined in Network.HTTP.Types.Header Methods compare :: ByteRange -> ByteRange -> Ordering # (<) :: ByteRange -> ByteRange -> Bool # (<=) :: ByteRange -> ByteRange -> Bool # (>) :: ByteRange -> ByteRange -> Bool # (>=) :: ByteRange -> ByteRange -> Bool # max :: ByteRange -> ByteRange -> ByteRange # min :: ByteRange -> ByteRange -> ByteRange #
type Rep ByteRange # | Since: 0.12.4
Instance details Defined in Network.HTTP.Types.Header type Rep ByteRange = D1 ('MetaData "ByteRange" "Network.HTTP.Types.Header" "http-types-0.12.4-HhEPaOzd8crnbrvqiOppv" 'False) (C1 ('MetaCons "ByteRangeFrom" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Integer)) :+: (C1 ('MetaCons "ByteRangeFromTo" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Integer) :*: S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Integer)) :+: C1 ('MetaCons "ByteRangeSuffix" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Integer))))

renderByteRangeBuilder :: ByteRange -> Builder #

Turns a byte range into a byte string `Builder`.

Since: 0.6.11

renderByteRange :: ByteRange -> ByteString #

Renders a byte range into a `ByteString`.

    >>> renderByteRange (ByteRangeFrom 2048)
    "2048-"

Since: 0.6.11

type ByteRanges = [ByteRange] #

A list of byte ranges.

Since: 0.6.11

renderByteRangesBuilder :: ByteRanges -> Builder #

Turns a list of byte ranges into a byte string `Builder`.

Since: 0.6.11

renderByteRanges :: ByteRanges -> ByteString #

Renders a list of byte ranges into a `ByteString`.

    >>> renderByteRanges [ByteRangeFrom 2048, ByteRangeSuffix 20]
    "bytes=2048-,-20"

Since: 0.6.11

parseByteRanges :: ByteString -> Maybe ByteRanges #

Parse the value of a Range header into a `ByteRanges`.

    >>> parseByteRanges "error"
    Nothing
    >>> parseByteRanges "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]

Since: 0.9.1