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) Source #

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 Source #

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] Source #

A list of `Header`s.

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

type ResponseHeaders = [Header] Source #

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 Source #

Accept

Since: 0.7.0

hAcceptCharset :: HeaderName Source #

Accept-Charset

Since: 0.9

hAcceptEncoding :: HeaderName Source #

Accept-Encoding

Since: 0.9

hAcceptLanguage :: HeaderName Source #

Accept-Language

Since: 0.7.0

hAcceptRanges :: HeaderName Source #

Accept-Ranges

Since: 0.9

hAge :: HeaderName Source #

Age

Since: 0.9

hAllow :: HeaderName Source #

Allow

Since: 0.9

hAuthorization :: HeaderName Source #

Authorization

Since: 0.7.0

hCacheControl :: HeaderName Source #

Cache-Control

Since: 0.7.0

hConnection :: HeaderName Source #

Connection

Since: 0.7.0

hContentDisposition :: HeaderName Source #

Content-Disposition

Since: 0.10

hContentEncoding :: HeaderName Source #

Content-Encoding

Since: 0.7.0

hContentLanguage :: HeaderName Source #

Content-Language

Since: 0.9

hContentLength :: HeaderName Source #

Content-Length

Since: 0.7.0

hContentLocation :: HeaderName Source #

Content-Location

Since: 0.9

hContentMD5 :: HeaderName Source #

Content-MD5

This header has been obsoleted in RFC 9110.

Since: 0.7.0

hContentRange :: HeaderName Source #

Content-Range

Since: 0.9

hContentType :: HeaderName Source #

Content-Type

Since: 0.7.0

hCookie :: HeaderName Source #

Cookie

Since: 0.7.0

hDate :: HeaderName Source #

Date

Since: 0.7.0

hETag :: HeaderName Source #

ETag

Since: 0.9

hExpect :: HeaderName Source #

Expect

Since: 0.9

hExpires :: HeaderName Source #

Expires

Since: 0.9

hFrom :: HeaderName Source #

From

Since: 0.9

hHost :: HeaderName Source #

Host

Since: 0.9

hIfMatch :: HeaderName Source #

If-Match

Since: 0.9

hIfModifiedSince :: HeaderName Source #

If-Modified-Since

Since: 0.7.0

hIfNoneMatch :: HeaderName Source #

If-None-Match

Since: 0.9

hIfRange :: HeaderName Source #

If-Range

Since: 0.7.0

hIfUnmodifiedSince :: HeaderName Source #

If-Unmodified-Since

Since: 0.9

hLastModified :: HeaderName Source #

Last-Modified

Since: 0.7.0

hLocation :: HeaderName Source #

Location

Since: 0.7.1

hMaxForwards :: HeaderName Source #

Max-Forwards

Since: 0.9

hMIMEVersion :: HeaderName Source #

MIME-Version

Since: 0.10

hOrigin :: HeaderName Source #

Origin

Since: 0.10

hPragma :: HeaderName Source #

Pragma

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

Since: 0.9

hPrefer :: HeaderName Source #

Prefer

Since: 0.12.2

hPreferenceApplied :: HeaderName Source #

Preference-Applied

Since: 0.12.2

hProxyAuthenticate :: HeaderName Source #

Proxy-Authenticate

Since: 0.9

hProxyAuthorization :: HeaderName Source #

Proxy-Authorization

Since: 0.9

hRange :: HeaderName Source #

Range

Since: 0.7.0

hReferer :: HeaderName Source #

Referer

Since: 0.7.0

hRetryAfter :: HeaderName Source #

Retry-After

Since: 0.9

hServer :: HeaderName Source #

Server

Since: 0.7.1

hSetCookie :: HeaderName Source #

Set-Cookie

Since: 0.10

hTE :: HeaderName Source #

TE

Since: 0.9

hTrailer :: HeaderName Source #

Trailer

Since: 0.9

hTransferEncoding :: HeaderName Source #

Transfer-Encoding

Since: 0.9

hUpgrade :: HeaderName Source #

Upgrade

Since: 0.9

hUserAgent :: HeaderName Source #

User-Agent

Since: 0.7.0

hVary :: HeaderName Source #

Vary

Since: 0.9

hVia :: HeaderName Source #

Via

Since: 0.9

hWWWAuthenticate :: HeaderName Source #

WWW-Authenticate

Since: 0.9

hWarning :: HeaderName Source #

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 Source #

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 Source # | 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 Source #

gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c ByteRange Source #

toConstr :: ByteRange -> Constr Source #

dataTypeOf :: ByteRange -> DataType Source #

dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c ByteRange) Source #

dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c ByteRange) Source #

gmapT :: (forall b. Data b => b -> b) -> ByteRange -> ByteRange Source #

gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> ByteRange -> r Source #

gmapQr :: forall r r'. (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> ByteRange -> r Source #

gmapQ :: (forall d. Data d => d -> u) -> ByteRange -> [u] Source #

gmapQi :: Int -> (forall d. Data d => d -> u) -> ByteRange -> u Source #

gmapM :: Monad m => (forall d. Data d => d -> m d) -> ByteRange -> m ByteRange Source #

gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> ByteRange -> m ByteRange Source #

gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> ByteRange -> m ByteRange Source #

Generic ByteRange Source # |

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-1OvlBK9BqlVDFTI6Nz1ui2" '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 Source #

to :: Rep ByteRange x -> ByteRange Source #

Show ByteRange Source # | Since: 0.8.4
Instance details Defined in Network.HTTP.Types.Header Methods showsPrec :: Int -> ByteRange -> ShowS Source # show :: ByteRange -> String Source # showList :: [ByteRange] -> ShowS Source #
Eq ByteRange Source # | Since: 0.8.4
Instance details Defined in Network.HTTP.Types.Header Methods (==) :: ByteRange -> ByteRange -> Bool Source # (/=) :: ByteRange -> ByteRange -> Bool Source #
Ord ByteRange Source # | Since: 0.8.4

Instance details

Defined in Network.HTTP.Types.Header

Methods

compare :: ByteRange -> ByteRange -> Ordering Source #

(<) :: ByteRange -> ByteRange -> Bool Source #

(<=) :: ByteRange -> ByteRange -> Bool Source #

(>) :: ByteRange -> ByteRange -> Bool Source #

(>=) :: ByteRange -> ByteRange -> Bool Source #

max :: ByteRange -> ByteRange -> ByteRange Source #

min :: ByteRange -> ByteRange -> ByteRange Source #

type Rep ByteRange Source # | 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-1OvlBK9BqlVDFTI6Nz1ui2" '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 Source #

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

Since: 0.6.11

renderByteRange :: ByteRange -> ByteString Source #

Renders a byte range into a `ByteString`.

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

Since: 0.6.11

type ByteRanges = [ByteRange] Source #

A list of byte ranges.

Since: 0.6.11

renderByteRangesBuilder :: ByteRanges -> Builder Source #

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

Since: 0.6.11

renderByteRanges :: ByteRanges -> ByteString Source #

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 Source #

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