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

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

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

type ResponseHeaders = [Header] #

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.

hAccept :: HeaderName #

Accept

Since: 0.7.0

hAge :: HeaderName #

Age

Since: 0.9

hAllow :: HeaderName #

Allow

Since: 0.9

hContentMD5 :: HeaderName #

Content-MD5

This header has been obsoleted in RFC 9110.

Since: 0.7.0

hCookie :: HeaderName #

Cookie

Since: 0.7.0

hDate :: HeaderName #

Date

Since: 0.7.0

hETag :: HeaderName #

ETag

Since: 0.9

hFrom :: HeaderName #

From

Since: 0.9

hHost :: HeaderName #

Host

Since: 0.9

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

hRange :: HeaderName #

Range

Since: 0.7.0

hServer :: HeaderName #

Server

Since: 0.7.1

hTE :: HeaderName #

TE

Since: 0.9

hVary :: HeaderName #

Vary

Since: 0.9

hVia :: HeaderName #

Via

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

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

Show ByteRange #

Since: 0.8.4

Instance details

Defined in Network.HTTP.Types.Header

Eq ByteRange #

Since: 0.8.4

Instance details

Defined in Network.HTTP.Types.Header

Ord ByteRange #

Since: 0.8.4

Instance details

Defined in Network.HTTP.Types.Header

type Rep ByteRange #

Since: 0.12.4

Instance details

Defined in Network.HTTP.Types.Header

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