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

Network.HTTP.Types.Header

Description

Type and constants for handling HTTP header fields.

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

Synopsis

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

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

type ResponseHeaders = [Header] Source #

A list of Headers.

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.

hAge :: HeaderName Source #

Age

Since: 0.9

hContentMD5 :: HeaderName Source #

Content-MD5

This header has been obsoleted in RFC 9110.

Since: 0.7.0

hDate :: HeaderName Source #

Date

Since: 0.7.0

hPragma :: HeaderName Source #

Pragma

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

Since: 0.9

hTE :: HeaderName Source #

TE

Since: 0.9

hVia :: HeaderName Source #

Via

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

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 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-9oRfzVPes8mH5fGJMdovux" '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 Source #

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

Since: 0.8.4

Instance details

Defined in Network.HTTP.Types.Header

Methods

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

(/=) :: ByteRange -> ByteRange -> Bool

Ord ByteRange Source #

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 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-9oRfzVPes8mH5fGJMdovux" '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