Safe Haskell | None |
---|---|
Language | Haskell2010 |
Framing in HTTP/2.
- data Frame = Frame {}
- data FrameHeader = FrameHeader {
- payloadLength :: Int
- flags :: FrameFlags
- streamId :: StreamId
- data FramePayload
- = DataFrame ByteString
- | HeadersFrame (Maybe Priority) HeaderBlockFragment
- | PriorityFrame Priority
- | RSTStreamFrame ErrorCodeId
- | SettingsFrame SettingsList
- | PushPromiseFrame StreamId HeaderBlockFragment
- | PingFrame ByteString
- | GoAwayFrame StreamId ErrorCodeId ByteString
- | WindowUpdateFrame WindowSize
- | ContinuationFrame HeaderBlockFragment
- | UnknownFrame FrameType ByteString
- isPaddingDefined :: FramePayload -> Bool
- encodeFrame :: EncodeInfo -> FramePayload -> ByteString
- encodeFrameChunks :: EncodeInfo -> FramePayload -> [ByteString]
- encodeFrameHeader :: FrameTypeId -> FrameHeader -> ByteString
- encodeFrameHeaderBuf :: FrameTypeId -> FrameHeader -> Ptr Word8 -> IO ()
- encodeFramePayload :: EncodeInfo -> FramePayload -> (FrameHeader, [ByteString])
- data EncodeInfo = EncodeInfo {}
- encodeInfo :: (FrameFlags -> FrameFlags) -> Int -> EncodeInfo
- decodeFrame :: Settings -> ByteString -> Either HTTP2Error Frame
- decodeFrameHeader :: ByteString -> (FrameTypeId, FrameHeader)
- checkFrameHeader :: Settings -> (FrameTypeId, FrameHeader) -> Either HTTP2Error (FrameTypeId, FrameHeader)
- decodeFramePayload :: FrameTypeId -> FramePayloadDecoder
- type FramePayloadDecoder = FrameHeader -> ByteString -> Either HTTP2Error FramePayload
- decodeDataFrame :: FramePayloadDecoder
- decodeHeadersFrame :: FramePayloadDecoder
- decodePriorityFrame :: FramePayloadDecoder
- decoderstStreamFrame :: FramePayloadDecoder
- decodeSettingsFrame :: FramePayloadDecoder
- decodePushPromiseFrame :: FramePayloadDecoder
- decodePingFrame :: FramePayloadDecoder
- decodeGoAwayFrame :: FramePayloadDecoder
- decodeWindowUpdateFrame :: FramePayloadDecoder
- decodeContinuationFrame :: FramePayloadDecoder
- data FrameTypeId
- framePayloadToFrameTypeId :: FramePayload -> FrameTypeId
- type FrameType = Word8
- fromFrameTypeId :: FrameTypeId -> FrameType
- toFrameTypeId :: FrameType -> FrameTypeId
- type HeaderBlockFragment = ByteString
- type Padding = ByteString
- type Weight = Int
- data Priority = Priority {}
- defaultPriority :: Priority
- highestPriority :: Priority
- type StreamId = Int
- isControl :: StreamId -> Bool
- isRequest :: StreamId -> Bool
- isResponse :: StreamId -> Bool
- testExclusive :: Int -> Bool
- setExclusive :: Int -> Int
- clearExclusive :: Int -> Int
- type FrameFlags = Word8
- defaultFlags :: FrameFlags
- testEndStream :: FrameFlags -> Bool
- testAck :: FrameFlags -> Bool
- testEndHeader :: FrameFlags -> Bool
- testPadded :: FrameFlags -> Bool
- testPriority :: FrameFlags -> Bool
- setEndStream :: FrameFlags -> FrameFlags
- setAck :: FrameFlags -> FrameFlags
- setEndHeader :: FrameFlags -> FrameFlags
- setPadded :: FrameFlags -> FrameFlags
- setPriority :: FrameFlags -> FrameFlags
- type SettingsList = [(SettingsKeyId, SettingsValue)]
- type SettingsValue = Int
- data SettingsKeyId
- fromSettingsKeyId :: SettingsKeyId -> Word16
- toSettingsKeyId :: Word16 -> Maybe SettingsKeyId
- checkSettingsList :: SettingsList -> Maybe HTTP2Error
- data Settings = Settings {}
- defaultSettings :: Settings
- updateSettings :: Settings -> SettingsList -> Settings
- type WindowSize = Int
- defaultInitialWindowSize :: WindowSize
- maxWindowSize :: WindowSize
- isWindowOverflow :: WindowSize -> Bool
- recommendedConcurrency :: Int
- type ErrorCode = Word32
- data ErrorCodeId
- fromErrorCodeId :: ErrorCodeId -> ErrorCode
- toErrorCodeId :: ErrorCode -> ErrorCodeId
- data HTTP2Error
- errorCodeId :: HTTP2Error -> ErrorCodeId
- connectionPreface :: ByteString
- connectionPrefaceLength :: Int
- frameHeaderLength :: Int
- maxPayloadLength :: Int
Frame
The data type for HTTP/2 frames.
data FrameHeader Source
The data type for HTTP/2 frame headers.
FrameHeader | |
|
data FramePayload Source
The data type for HTTP/2 frame payloads.
isPaddingDefined :: FramePayload -> Bool Source
Checking if padding is defined in this frame type.
Encoding
encodeFrame :: EncodeInfo -> FramePayload -> ByteString Source
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] Source
Encoding an HTTP/2 frame to [ByteString
].
This is suitable for sendMany.
encodeFrameHeader :: FrameTypeId -> FrameHeader -> ByteString Source
Encoding an HTTP/2 frame header. The frame header must be completed.
encodeFrameHeaderBuf :: FrameTypeId -> FrameHeader -> Ptr Word8 -> IO () Source
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]) Source
Encoding an HTTP/2 frame payload. This returns a complete frame header and chunks of payload.
data EncodeInfo Source
Auxiliary information for frame encoding.
EncodeInfo | |
|
:: (FrameFlags -> FrameFlags) | |
-> Int | stream identifier |
-> EncodeInfo |
A smart builder of EncodeInfo
.
>>>
encodeInfo setAck 0
EncodeInfo {encodeFlags = 1, encodeStreamId = 0, encodePadding = Nothing}
Decoding
:: Settings | HTTP/2 settings |
-> ByteString | Input byte-stream |
-> Either HTTP2Error 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 -> (FrameTypeId, FrameHeader) Source
Decoding an HTTP/2 frame header. Must supply 9 bytes.
checkFrameHeader :: Settings -> (FrameTypeId, FrameHeader) -> Either HTTP2Error (FrameTypeId, FrameHeader) Source
Checking a frame header and reporting an error if any.
>>>
checkFrameHeader defaultSettings (FrameData,(FrameHeader 100 0 0))
Left (ConnectionError ProtocolError "cannot used in control stream")
Decoding payload
decodeFramePayload :: FrameTypeId -> FramePayloadDecoder Source
Decoding an HTTP/2 frame payload.
type FramePayloadDecoder = FrameHeader -> ByteString -> Either HTTP2Error FramePayload Source
Frame type ID
data FrameTypeId Source
framePayloadToFrameTypeId :: FramePayload -> FrameTypeId Source
Getting FrameType
from FramePayload
.
>>>
framePayloadToFrameTypeId (DataFrame "body")
FrameData
Frame type
fromFrameTypeId :: FrameTypeId -> FrameType Source
>>>
fromFrameTypeId FrameData
0>>>
fromFrameTypeId FrameContinuation
9>>>
fromFrameTypeId (FrameUnknown 10)
10
toFrameTypeId :: FrameType -> FrameTypeId Source
>>>
toFrameTypeId 0
FrameData>>>
toFrameTypeId 9
FrameContinuation>>>
toFrameTypeId 10
FrameUnknown 10
Types
type HeaderBlockFragment = ByteString Source
type Padding = ByteString Source
defaultPriority :: Priority Source
Default priority which depends on stream 0.
>>>
defaultPriority
Priority {exclusive = False, streamDependency = 0, weight = 16}
highestPriority :: Priority Source
Highest priority which depends on stream 0.
>>>
highestPriority
Priority {exclusive = False, streamDependency = 0, weight = 256}
Stream identifier
isResponse :: StreamId -> Bool Source
>>>
isResponse 0
False>>>
isResponse 2
True
Stream identifier related
testExclusive :: Int -> Bool Source
setExclusive :: Int -> Int Source
clearExclusive :: Int -> Int Source
Flags
type FrameFlags = Word8 Source
defaultFlags :: FrameFlags Source
>>>
defaultFlags
0
testEndStream :: FrameFlags -> Bool Source
>>>
testEndStream 0x1
True
testAck :: FrameFlags -> Bool Source
>>>
testAck 0x1
True
testEndHeader :: FrameFlags -> Bool Source
>>>
testEndHeader 0x4
True
testPadded :: FrameFlags -> Bool Source
>>>
testPadded 0x8
True
testPriority :: FrameFlags -> Bool Source
>>>
testPriority 0x20
True
setEndStream :: FrameFlags -> FrameFlags Source
>>>
setEndStream 0
1
setAck :: FrameFlags -> FrameFlags Source
>>>
setAck 0
1
setEndHeader :: FrameFlags -> FrameFlags Source
>>>
setEndHeader 0
4
setPadded :: FrameFlags -> FrameFlags Source
>>>
setPadded 0
8
setPriority :: FrameFlags -> FrameFlags Source
>>>
setPriority 0
32
SettingsList
type SettingsList = [(SettingsKeyId, SettingsValue)] Source
Settings containing raw values.
type SettingsValue = Int Source
data SettingsKeyId Source
fromSettingsKeyId :: SettingsKeyId -> Word16 Source
>>>
fromSettingsKeyId SettingsHeaderTableSize
1>>>
fromSettingsKeyId SettingsMaxHeaderBlockSize
6
toSettingsKeyId :: Word16 -> Maybe SettingsKeyId Source
>>>
toSettingsKeyId 0
Nothing>>>
toSettingsKeyId 1
Just SettingsHeaderTableSize>>>
toSettingsKeyId 6
Just SettingsMaxHeaderBlockSize>>>
toSettingsKeyId 7
Nothing
checkSettingsList :: SettingsList -> Maybe HTTP2Error Source
Checking SettingsList
and reporting an error if any.
>>>
checkSettingsList [(SettingsEnablePush,2)]
Just (ConnectionError ProtocolError "enable push must be 0 or 1")
Settings
Cooked version of settings. This is suitable to be stored in a HTTP/2 context.
defaultSettings :: Settings Source
The default settings.
>>>
defaultSettings
Settings {headerTableSize = 4096, enablePush = True, maxConcurrentStreams = Nothing, initialWindowSize = 65535, maxFrameSize = 16384, maxHeaderBlockSize = Nothing}
updateSettings :: Settings -> SettingsList -> Settings Source
Updating settings.
>>>
updateSettings defaultSettings [(SettingsEnablePush,0),(SettingsMaxHeaderBlockSize,200)]
Settings {headerTableSize = 4096, enablePush = False, maxConcurrentStreams = Nothing, initialWindowSize = 65535, maxFrameSize = 16384, maxHeaderBlockSize = Just 200}
Window
type WindowSize = Int Source
defaultInitialWindowSize :: WindowSize Source
The default initial window size.
>>>
defaultInitialWindowSize
65535
maxWindowSize :: WindowSize Source
The maximum window size.
>>>
maxWindowSize
2147483647
isWindowOverflow :: WindowSize -> Bool Source
Checking if a window size exceeds the maximum window size.
>>>
isWindowOverflow 10
False>>>
isWindowOverflow maxWindowSize
False>>>
isWindowOverflow (maxWindowSize + 1)
True
Misc
recommendedConcurrency :: Int Source
Default concurrency.
>>>
recommendedConcurrency
100
Error code
data ErrorCodeId Source
fromErrorCodeId :: ErrorCodeId -> ErrorCode Source
>>>
fromErrorCodeId NoError
0>>>
fromErrorCodeId InadequateSecurity
12
toErrorCodeId :: ErrorCode -> ErrorCodeId Source
>>>
toErrorCodeId 0
NoError>>>
toErrorCodeId 0xc
InadequateSecurity>>>
toErrorCodeId 0xe
UnknownErrorCode 14
Error
data HTTP2Error Source
The connection error or the stream error.
errorCodeId :: HTTP2Error -> ErrorCodeId Source
Obtaining ErrorCodeId
from HTTP2Error
.
Magic
connectionPreface :: ByteString Source
The preface of HTTP/2.
>>>
connectionPreface
"PRI * HTTP/2.0\r\n\r\nSM\r\n\r\n"
connectionPrefaceLength :: Int Source
Length of the preface.
>>>
connectionPrefaceLength
24
frameHeaderLength :: Int Source
The length of HTTP/2 frame header.
>>>
frameHeaderLength
9
maxPayloadLength :: Int Source
The maximum length of HTTP/2 payload.
>>>
maxPayloadLength
16384