Skip to content
CryoCryo home
Stdlibnet::http2

frame

import std::net::http2::frame; · source

HTTP/2 framing, RFC 7540 sections 4 and 6. Every frame is a 9-octet header — a 24-bit length, an 8-bit type, an 8-bit flags field, and a 31-bit stream identifier whose reserved top bit is cleared — followed by length octets of payload. Http2Connection drives all of this; the page is for code that speaks the wire format itself.

Types

Frame

type struct Frame {
    ftype:     u8;
    flags:     u8;
    stream_id: u32;
    payload:   Array<u8>;
}

One decoded frame, owning its payload bytes, as read_http2_frame returns it; the type itself is internal to the library. has_flag(flag) tests a flag bit; a flag's meaning depends on the frame type — FLAG_ACK and FLAG_END_STREAM are the same bit — so check ftype first.

Properties

PropertyType
ftypeu8
flagsu8
stream_idu32
payloadArray<u8>

Methods

has_flag(&this, flag: u8) -> boolean;

Whether any bit of flag is set in the frame's flags. A flag's meaning depends on the frame type: FLAG_ACK and FLAG_END_STREAM are the same bit, so check ftype first.

Reading and queuing frames

implement struct BufferedStream<S> {
    queue_http2_frame(mut &this, ftype: u8, flags: u8, stream_id: u32, payload: &Slice<u8>) -> Result<(), IoError>;
}

Both directions are methods on BufferedStream<S>, beside HTTP/1.1's read_request and WebSocket's read_frame, and for the same reasons. Reading is a method because only the receiver is re-supplied on every poll (E0455). Queuing is synchronous: queue_http2_frame builds the header and payload into pending() with no suspension point inside it, and the caller suspends once, in flush — which is what lets a HEADERS block and its CONTINUATION fragments go out in one transport operation. The names carry http2 because BufferedStream<S> hosts the framing for three protocols, and WebSocket's ws::frame, internal to the library, already owns read_frame and queue_frame.

read_http2_frame(max_payload) rejects a payload longer than max_payload — the negotiated SETTINGS_MAX_FRAME_SIZE — or a fixed hard backstop, whichever is smaller.

Constants

The frame types (FRAME_*), the flag bits (FLAG_*), and the error codes a RST_STREAM or GOAWAY frame carries.

const FRAME_HEADER_LENGTH: i64 = 9;
const FRAME_DATA:          u8  = 0x0;
const FRAME_HEADERS:       u8  = 0x1;
const FRAME_PRIORITY:      u8  = 0x2;
const FRAME_RST_STREAM:    u8  = 0x3;
const FRAME_SETTINGS:      u8  = 0x4;
const FRAME_PUSH_PROMISE:  u8  = 0x5;
const FRAME_PING:          u8  = 0x6;
const FRAME_GOAWAY:        u8  = 0x7;
const FRAME_WINDOW_UPDATE: u8  = 0x8;
const FRAME_CONTINUATION:  u8  = 0x9;
const FLAG_ACK:            u8  = 1 << 0;
const FLAG_END_STREAM:     u8  = 1 << 0;
const FLAG_END_HEADERS:    u8  = 1 << 2;
const FLAG_PADDED:         u8  = 1 << 3;
const FLAG_PRIORITY:       u8  = 1 << 5;
const NO_ERROR:            u32 = 0x0;
const PROTOCOL_ERROR:      u32 = 0x1;
const INTERNAL_ERROR:      u32 = 0x2;
const FLOW_CONTROL_ERROR:  u32 = 0x3;
const SETTINGS_TIMEOUT:    u32 = 0x4;
const STREAM_CLOSED:       u32 = 0x5;
const FRAME_SIZE_ERROR:    u32 = 0x6;
const REFUSED_STREAM:      u32 = 0x7;
const CANCEL:              u32 = 0x8;
const COMPRESSION_ERROR:   u32 = 0x9;
const CONNECT_ERROR:       u32 = 0xa;
const ENHANCE_YOUR_CALM:   u32 = 0xb;
const INADEQUATE_SECURITY: u32 = 0xc;
const HTTP_1_1_REQUIRED:   u32 = 0xd;