http2-5.2.1: HTTP/2 library
Safe HaskellNone
LanguageHaskell2010

Network.HTTP2.Frame

Description

Synopsis

Frame

data Frame #

The data type for HTTP/2 frames.

Instances

Instances details
Read Frame # 
Instance details

Defined in Network.HTTP2.Frame.Types

Show Frame # 
Instance details

Defined in Network.HTTP2.Frame.Types

Methods

showsPrec :: Int -> Frame -> ShowS #

show :: Frame -> String #

showList :: [Frame] -> ShowS #

Eq Frame # 
Instance details

Defined in Network.HTTP2.Frame.Types

Methods

(==) :: Frame -> Frame -> Bool #

(/=) :: Frame -> Frame -> Bool #

data FrameHeader #

The data type for HTTP/2 frame headers.

type HeaderBlockFragment = ByteString #

The type for fragments of a header encoded with HPACK.

type Padding = ByteString #

The type for padding in payloads.

isPaddingDefined :: FramePayload -> Bool #

Checking if padding is defined in this frame type.

>>> isPaddingDefined $ DataFrame ""
True
>>> isPaddingDefined $ PingFrame ""
False

Encoding

encodeFrame :: EncodeInfo -> FramePayload -> ByteString #

Encoding an HTTP/2 frame to ByteString. This function is not efficient enough for high performace program because of the concatenation of ByteString.

>>> encodeFrame (encodeInfo id 1) (DataFrame "body")
"\NUL\NUL\EOT\NUL\NUL\NUL\NUL\NUL\SOHbody"

encodeFrameChunks :: EncodeInfo -> FramePayload -> [ByteString] #

Encoding an HTTP/2 frame to [ByteString]. This is suitable for sendMany.

encodeFrameHeader :: FrameType -> FrameHeader -> ByteString #

Encoding an HTTP/2 frame header. The frame header must be completed.

encodeFrameHeaderBuf :: FrameType -> FrameHeader -> Ptr Word8 -> IO () #

Writing an encoded HTTP/2 frame header to the buffer. The length of the buffer must be larger than or equal to 9 bytes.

encodeFramePayload :: EncodeInfo -> FramePayload -> (FrameHeader, [ByteString]) #

Encoding an HTTP/2 frame payload. This returns a complete frame header and chunks of payload.

data EncodeInfo #

Auxiliary information for frame encoding.

Constructors

EncodeInfo 

Fields

  • encodeFlags :: FrameFlags

    Flags to be set in a frame header

  • encodeStreamId :: StreamId

    Stream id to be set in a frame header

  • encodePadding :: Maybe Padding

    Padding if any. In the case where this value is set but the priority flag is not set, this value gets preference over the priority flag. So, if this value is set, the priority flag is also set.

encodeInfo #

Arguments

:: (FrameFlags -> FrameFlags) 
-> Int

stream identifier

-> EncodeInfo 

A smart builder of EncodeInfo.

>>> encodeInfo setAck 0
EncodeInfo {encodeFlags = 1, encodeStreamId = 0, encodePadding = Nothing}

decodeFrame #

Arguments

:: ByteString

Input byte-stream

-> Either FrameDecodeError Frame

Decoded frame

Decoding an HTTP/2 frame to ByteString. The second argument must be include the entire of frame. So, this function is not useful for real applications but useful for testing.

decodeFrameHeader :: ByteString -> (FrameType, FrameHeader) #

Decoding an HTTP/2 frame header. Must supply 9 bytes.

checkFrameHeader :: (FrameType, FrameHeader) -> Either FrameDecodeError (FrameType, FrameHeader) #

Checking a frame header and reporting an error if any.

>>> checkFrameHeader (FrameData,(FrameHeader 100 0 0))
Left (FrameDecodeError ProtocolError 0 "cannot used in control stream")

decodeFramePayload :: FrameType -> FramePayloadDecoder #

Decoding an HTTP/2 frame payload. This function is considered to return a frame payload decoder according to a frame type.

type FramePayloadDecoder = FrameHeader -> ByteString -> Either FrameDecodeError FramePayload #

The type for frame payload decoder.

decodeDataFrame :: FramePayloadDecoder #

Frame payload decoder for DATA frame.

decodeHeadersFrame :: FramePayloadDecoder #

Frame payload decoder for HEADERS frame.

decodePriorityFrame :: FramePayloadDecoder #

Frame payload decoder for PRIORITY frame.

decodeRSTStreamFrame :: FramePayloadDecoder #

Frame payload decoder for RST_STREAM frame.

decodeSettingsFrame :: FramePayloadDecoder #

Frame payload decoder for SETTINGS frame.

decodePushPromiseFrame :: FramePayloadDecoder #

Frame payload decoder for PUSH_PROMISE frame.

decodePingFrame :: FramePayloadDecoder #

Frame payload decoder for PING frame.

decodeGoAwayFrame :: FramePayloadDecoder #

Frame payload decoder for GOAWAY frame.

decodeWindowUpdateFrame :: FramePayloadDecoder #

Frame payload decoder for WINDOW_UPDATE frame.

decodeContinuationFrame :: FramePayloadDecoder #

Frame payload decoder for CONTINUATION frame.

Frame type

newtype FrameType #

The type for raw frame type.

Constructors

FrameType Word8 

Bundled Patterns

pattern FrameData :: FrameType 
pattern FrameHeaders :: FrameType 
pattern FramePriority :: FrameType 
pattern FrameRSTStream :: FrameType 
pattern FrameSettings :: FrameType 
pattern FramePushPromise :: FrameType 
pattern FramePing :: FrameType 
pattern FrameGoAway :: FrameType 
pattern FrameWindowUpdate :: FrameType 
pattern FrameContinuation :: FrameType 

fromFrameType :: FrameType -> Word8 #

Converting FrameType to Word8.

>>> fromFrameType FrameData
0
>>> fromFrameType FrameContinuation
9

framePayloadToFrameType :: FramePayload -> FrameType #

Getting FrameType from FramePayload.

>>> framePayloadToFrameType (DataFrame "body")
FrameData

Priority

data Priority #

Type for stream priority. Deprecated in RFC 9113 but provided for FrameHeaders.

Constructors

Priority 

Instances

Instances details
Read Priority # 
Instance details

Defined in Network.HTTP2.Frame.Types

Show Priority # 
Instance details

Defined in Network.HTTP2.Frame.Types

Eq Priority # 
Instance details

Defined in Network.HTTP2.Frame.Types

type Weight = Int #

The type for weight in priority. Its values are from 1 to 256. Deprecated in RFC 9113.

Stream identifier

type StreamId = Int #

The type for stream identifier

isControl :: StreamId -> Bool #

Checking if the stream identifier for control.

>>> isControl 0
True
>>> isControl 1
False

isClientInitiated :: StreamId -> Bool #

Checking if the stream identifier is from a client.

>>> isClientInitiated 0
False
>>> isClientInitiated 1
True

isServerInitiated :: StreamId -> Bool #

Checking if the stream identifier is from a server.

>>> isServerInitiated 0
False
>>> isServerInitiated 2
True

Stream identifier related

testExclusive :: StreamId -> Bool #

Checking if the exclusive flag is set.

setExclusive :: StreamId -> StreamId #

Setting the exclusive flag.

clearExclusive :: StreamId -> StreamId #

Clearing the exclusive flag.

Flags

type FrameFlags = Word8 #

The type for flags.

defaultFlags :: FrameFlags #

The initial value of flags. No flags are set.

>>> defaultFlags
0

testEndStream :: FrameFlags -> Bool #

Checking if the END_STREAM flag is set. >>> testEndStream 0x1 True

testAck :: FrameFlags -> Bool #

Checking if the ACK flag is set. >>> testAck 0x1 True

testEndHeader :: FrameFlags -> Bool #

Checking if the END_HEADERS flag is set.

>>> testEndHeader 0x4
True

testPadded :: FrameFlags -> Bool #

Checking if the PADDED flag is set.

>>> testPadded 0x8
True

testPriority :: FrameFlags -> Bool #

Checking if the PRIORITY flag is set.

>>> testPriority 0x20
True

setEndStream :: FrameFlags -> FrameFlags #

Setting the END_STREAM flag.

>>> setEndStream 0
1

setAck :: FrameFlags -> FrameFlags #

Setting the ACK flag.

>>> setAck 0
1

setEndHeader :: FrameFlags -> FrameFlags #

Setting the END_HEADERS flag.

>>> setEndHeader 0
4

setPadded :: FrameFlags -> FrameFlags #

Setting the PADDED flag.

>>> setPadded 0
8

setPriority :: FrameFlags -> FrameFlags #

Setting the PRIORITY flag.

>>> setPriority 0
32

SettingsList

type SettingsList = [(SettingsKey, SettingsValue)] #

Association list of SETTINGS.

type SettingsValue = Int #

The type for raw SETTINGS value.

Payload length

defaultPayloadLength :: Int #

The default payload length of HTTP/2 payload.

>>> defaultPayloadLength
16384

maxPayloadLength :: Int #

The maximum payload length of HTTP/2 payload.

>>> maxPayloadLength
16777215

Window

type WindowSize = Int #

Window size.

defaultWindowSize :: WindowSize #

The default initial window size.

>>> defaultWindowSize
65535

maxWindowSize :: WindowSize #

The maximum window size.

>>> maxWindowSize
2147483647

isWindowOverflow :: WindowSize -> Bool #

Checking if a window size exceeds the maximum window size.

>>> isWindowOverflow 10
False
>>> isWindowOverflow maxWindowSize
False
>>> isWindowOverflow (maxWindowSize + 1)
True

Error code

newtype ErrorCode #

The type for raw error code.

Constructors

ErrorCode Word32 

Bundled Patterns

pattern NoError :: ErrorCode

The type for error code. See https://www.rfc-editor.org/rfc/rfc9113#ErrorCodes.

pattern ProtocolError :: ErrorCode 
pattern InternalError :: ErrorCode 
pattern FlowControlError :: ErrorCode 
pattern SettingsTimeout :: ErrorCode 
pattern StreamClosed :: ErrorCode 
pattern FrameSizeError :: ErrorCode 
pattern RefusedStream :: ErrorCode 
pattern Cancel :: ErrorCode 
pattern CompressionError :: ErrorCode 
pattern ConnectError :: ErrorCode 
pattern EnhanceYourCalm :: ErrorCode 
pattern InadequateSecurity :: ErrorCode 
pattern HTTP11Required :: ErrorCode 

Predefined values

connectionPreface :: ByteString #

The preface of HTTP/2.

>>> connectionPreface
"PRI * HTTP/2.0\r\n\r\nSM\r\n\r\n"

connectionPrefaceLength :: Int #

Length of the preface.

>>> connectionPrefaceLength
24

frameHeaderLength :: Int #

The length of HTTP/2 frame header.

>>> frameHeaderLength
9

recommendedConcurrency :: Int #

Default concurrency.

>>> recommendedConcurrency
100

Deprecated