Skip to content

stdlib/http2View source ↗

http2

97 items · generated by scribe fromstdlib/http2.fd· synced 2026-11-15

stdlib/http297 items

Contents

H2_DATA:

pub const H2_DATA: i64 = 0; pub const H2_HEADERS: i64 = 1; pub const H2_PRIORITY: i64 = 2; pub const H2_RST_STREAM: i64 = 3; pub const H2_SETTINGS: i64 = 4; pub const H2_PUSH_PROMISE: i64 = 5; pub const H2_PING: i64 = 6; pub const H2_GOAWAY: i64 = 7; pub const H2_WINDOW_UPDATE: i64 = 8; pub const H2_CONTINUATION: i64 = 9;

Defined at line 44


H2_FLAG_END_STREAM:

pub const H2_FLAG_END_STREAM: i64 = 1; pub const H2_FLAG_ACK: i64 = 1; pub const H2_FLAG_END_HEADERS: i64 = 4; pub const H2_FLAG_PADDED: i64 = 8; pub const H2_FLAG_PRIORITY: i64 = 32;

Defined at line 45


H2_NO_ERROR:

pub const H2_NO_ERROR: i64 = 0; pub const H2_PROTOCOL_ERROR: i64 = 1; pub const H2_INTERNAL_ERROR: i64 = 2; pub const H2_FLOW_CONTROL_ERROR: i64 = 3; pub const H2_SETTINGS_TIMEOUT: i64 = 4; pub const H2_STREAM_CLOSED: i64 = 5; pub const H2_FRAME_SIZE_ERROR: i64 = 6; pub const H2_REFUSED_STREAM: i64 = 7; pub const H2_CANCEL: i64 = 8; pub const H2_COMPRESSION_ERROR: i64 = 9; pub const H2_CONNECT_ERROR: i64 = 10; pub const H2_ENHANCE_YOUR_CALM: i64 = 11; pub const H2_INADEQUATE_SECURITY: i64 = 12; pub const H2_HTTP_1_1_REQUIRED: i64 = 13;

Defined at line 46


H2_SETTINGS_HEADER_TABLE_SIZE:

pub const H2_SETTINGS_HEADER_TABLE_SIZE: i64 = 1; pub const H2_SETTINGS_ENABLE_PUSH: i64 = 2; pub const H2_SETTINGS_MAX_CONCURRENT_STREAMS: i64 = 3; pub const H2_SETTINGS_INITIAL_WINDOW_SIZE: i64 = 4; pub const H2_SETTINGS_MAX_FRAME_SIZE: i64 = 5; pub const H2_SETTINGS_MAX_HEADER_LIST_SIZE: i64 = 6;

Defined at line 47


H2_IDLE:

Stream states (5.1); reserved states never occur (no push).

pub const H2_IDLE: i64 = 0; pub const H2_OPEN: i64 = 1; pub const H2_HALF_CLOSED_LOCAL: i64 = 2; pub const H2_HALF_CLOSED_REMOTE: i64 = 3; pub const H2_CLOSED: i64 = 4;

Defined at line 49


H2_DEFAULT_WINDOW:

The default and largest window, the default frame size (6.5.2).

pub const H2_DEFAULT_WINDOW: i64 = 65535; pub const H2_MAX_WINDOW: i64 = 2147483647; pub const H2_DEFAULT_FRAME: i64 = 16384; pub const H2_MAX_FRAME: i64 = 16777215;

Defined at line 51


h2_preface

The client connection preface (3.4): “PRI * HTTP/2.0\r\n\r\nSM\r\n\r\n”.

pub fn h2_preface() -> Vec<i64> {

Returns: Vec<i64>

Defined at line 59


h2_type_name

Name of a frame type, for logs and tests.

pub fn h2_type_name(t: i64) -> str {

Parameters:

  • t: i64

Returns: str

Defined at line 64


h2_error_name

Name of an error code (7).

pub fn h2_error_name(e: i64) -> str {

Parameters:

  • e: i64

Returns: str

Defined at line 99


H2Frame

A frame. length is the payload’s length (also set when only the header was read); ftype -1 means no frame (not enough bytes).

pub struct H2Frame {

Fields:

NameType
lengthi64
ftypei64
flagsi64
streami64
payloadVec<i64>

Defined at line 149


h2_frame

pub fn h2_frame(ftype: i64, flags: i64, stream: i64, payload: Vec<i64>) -> H2Frame {

Parameters:

  • ftype: i64
  • flags: i64
  • stream: i64
  • payload: Vec<i64>

Returns: H2Frame

Defined at line 157


h2_put_frame

Append a frame’s 9-byte header and payload to out.

pub fn h2_put_frame(out: & mut Vec<i64>, f: H2Frame) {

Parameters:

  • out: & mut Vec<i64>
  • f: H2Frame

Defined at line 199


h2_frame_encode

A frame as bytes: header then payload.

pub fn h2_frame_encode(f: H2Frame) -> Vec<i64> {

Parameters:

  • f: H2Frame

Returns: Vec<i64>

Defined at line 211


h2_frame_header

The frame header at at (payload left empty): ftype -1 when fewer than 9 bytes are there. The reserved bit of the stream id is dropped (4.1).

pub fn h2_frame_header(b: Vec<i64>, at: i64) -> H2Frame {

Parameters:

  • b: Vec<i64>
  • at: i64

Returns: H2Frame

Defined at line 219


h2_frame_decode

The whole frame at at: ftype -1 when it is not all there yet.

pub fn h2_frame_decode(b: Vec<i64>, at: i64) -> H2Frame {

Parameters:

  • b: Vec<i64>
  • at: i64

Returns: H2Frame

Defined at line 229


h2_frames_decode

Every frame in b from at, in order (stops at an incomplete one).

pub fn h2_frames_decode(b: Vec<i64>, at: i64) -> Vec<H2Frame> {

Parameters:

  • b: Vec<i64>
  • at: i64

Returns: Vec<H2Frame>

Defined at line 239


h2_data_frame

DATA (6.1). pad > 0 adds PADDED with that many zero bytes.

pub fn h2_data_frame(stream: i64, data: Vec<i64>, end_stream: bool, pad: i64) -> H2Frame {

Parameters:

  • stream: i64
  • data: Vec<i64>
  • end_stream: bool
  • pad: i64

Returns: H2Frame

Defined at line 262


H2Priority

Priority fields of HEADERS and PRIORITY (5.3, deprecated by RFC 9113 but still on the wire). weight is 1..256.

pub struct H2Priority {

Fields:

NameType
exclusivebool
depi64
weighti64

Defined at line 279


h2_priority

pub fn h2_priority(exclusive: bool, dep: i64, weight: i64) -> H2Priority {

Parameters:

  • exclusive: bool
  • dep: i64
  • weight: i64

Returns: H2Priority

Defined at line 285


h2_no_priority

pub fn h2_no_priority() -> H2Priority {

Returns: H2Priority

Defined at line 291


h2_headers_frame

HEADERS (6.2) carrying a header block fragment.

pub fn h2_headers_frame(stream: i64, block: Vec<i64>, end_stream: bool, end_headers: bool) -> H2Frame {

Parameters:

  • stream: i64
  • block: Vec<i64>
  • end_stream: bool
  • end_headers: bool

Returns: H2Frame

Defined at line 307


h2_headers_frame_ex

HEADERS with padding (pad > 0) and priority fields (has_priority).

pub fn h2_headers_frame_ex(stream: i64, block: Vec<i64>, end_stream: bool, end_headers: bool, pad: i64, has_priority: bool, pr: H2Priority) -> H2Frame {

Parameters:

  • stream: i64
  • block: Vec<i64>
  • end_stream: bool
  • end_headers: bool
  • pad: i64
  • has_priority: bool
  • pr: H2Priority

Returns: H2Frame

Defined at line 312


h2_priority_frame

PRIORITY (6.3).

pub fn h2_priority_frame(stream: i64, pr: H2Priority) -> H2Frame {

Parameters:

  • stream: i64
  • pr: H2Priority

Returns: H2Frame

Defined at line 335


h2_rst_stream_frame

RST_STREAM (6.4).

pub fn h2_rst_stream_frame(stream: i64, code: i64) -> H2Frame {

Parameters:

  • stream: i64
  • code: i64

Returns: H2Frame

Defined at line 342


h2_settings_frame

SETTINGS (6.5) with these identifiers and values.

pub fn h2_settings_frame(ids: Vec<i64>, vals: Vec<i64>) -> H2Frame {

Parameters:

  • ids: Vec<i64>
  • vals: Vec<i64>

Returns: H2Frame

Defined at line 349


h2_settings_ack

The acknowledgement of a SETTINGS frame.

pub fn h2_settings_ack() -> H2Frame {

Returns: H2Frame

Defined at line 362


h2_ping_frame

PING (6.7): 8 opaque bytes (shorter data is padded with zeros).

pub fn h2_ping_frame(opaque: Vec<i64>, ack: bool) -> H2Frame {

Parameters:

  • opaque: Vec<i64>
  • ack: bool

Returns: H2Frame

Defined at line 367


h2_goaway_frame

GOAWAY (6.8).

pub fn h2_goaway_frame(last_stream: i64, code: i64, debug: str) -> H2Frame {

Parameters:

  • last_stream: i64
  • code: i64
  • debug: str

Returns: H2Frame

Defined at line 386


h2_window_update_frame

WINDOW_UPDATE (6.9) for a stream, or the connection (stream 0).

pub fn h2_window_update_frame(stream: i64, increment: i64) -> H2Frame {

Parameters:

  • stream: i64
  • increment: i64

Returns: H2Frame

Defined at line 395


h2_continuation_frame

CONTINUATION (6.10).

pub fn h2_continuation_frame(stream: i64, block: Vec<i64>, end_headers: bool) -> H2Frame {

Parameters:

  • stream: i64
  • block: Vec<i64>
  • end_headers: bool

Returns: H2Frame

Defined at line 402


H2Info

What a frame’s payload says. ok false: error is the error code and stream_error tells a stream error (RST_STREAM) from a connection error (GOAWAY). data is DATA’s data, the header block fragment of HEADERS and CONTINUATION, PING’s opaque bytes, or GOAWAY’s debug data.

pub struct H2Info {

Fields:

NameType
okbool
errori64
stream_errorbool
whystr
dataVec<i64>
padi64
has_prioritybool
priorityH2Priority
codei64
last_streami64
incrementi64
idsVec<i64>
valsVec<i64>

Defined at line 414


h2_parse

Parse and check a frame’s payload (RFC 9113 6). An unknown type is ok and carries nothing (it must be ignored, 5.5).

pub fn h2_parse(f: H2Frame) -> H2Info {

Parameters:

  • f: H2Frame

Returns: H2Info

Defined at line 454


h2_frame_describe

One line describing a frame (tests, logs).

pub fn h2_frame_describe(f: H2Frame) -> str {

Parameters:

  • f: H2Frame

Returns: str

Defined at line 589


H2Stream

A stream of a connection.

pub struct H2Stream {

Fields:

NameType
idi64
statei64
send_windowi64
recv_windowi64
namesVec<str>
valsVec<str>
got_headersbool
bodyVec<i64>
pendingVec<i64>
pending_endbool
handledbool
reseti64

Defined at line 639


H2Conn

One HTTP/2 connection, either end.

pub struct H2Conn {

Fields:

NameType
fdi64
clientbool
authoritystr
okbool
inbufVec<i64>
inposi64
outVec<i64>
encHpack
decHpack
peer_windowi64
peer_max_framei64
peer_max_streamsi64
send_windowi64
recv_windowi64
streamsVec<H2Stream>
next_idi64
last_peeri64
got_settingsbool
goawaybool
errori64
whystr
cont_streami64
cont_flagsi64
cont_blockVec<i64>

Defined at line 661


h2_conn_new

A connection over socket fd. With fd -1 nothing is read or written: frames queued by h2_send stay in out (tests feed h2_process by hand).

pub fn h2_conn_new(fd: i64, client: bool, authority: str) -> H2Conn {

Parameters:

  • fd: i64
  • client: bool
  • authority: str

Returns: H2Conn

Defined at line 707


h2_stream_index

Index of stream id in the table, -1 when it is not there (idle, or closed and forgotten).

pub fn h2_stream_index(c: & H2Conn, id: i64) -> i64 {

Parameters:

  • c: & H2Conn
  • id: i64

Returns: i64

Defined at line 719


h2_send

Queue a frame (written by h2_flush).

pub fn h2_send(c: & mut H2Conn, f: H2Frame) {

Parameters:

  • c: & mut H2Conn
  • f: H2Frame

Defined at line 731


h2_flush

Write the queued frames. False when the connection failed.

pub fn h2_flush(c: & mut H2Conn) -> bool {

Parameters:

  • c: & mut H2Conn

Returns: bool

Defined at line 736


h2_read_frame

Read the next frame (ftype -1 at the end of the input, on a timeout, or when the frame is larger than we allow: then c.error is set).

pub fn h2_read_frame(c: & mut H2Conn, timeout_ms: i64) -> H2Frame {

Parameters:

  • c: & mut H2Conn
  • timeout_ms: i64

Returns: H2Frame

Defined at line 787


h2_conn_error

A connection error (5.4.1): GOAWAY with the last stream the peer opened, then the connection is done.

pub fn h2_conn_error(c: & mut H2Conn, code: i64, why: str) {

Parameters:

  • c: & mut H2Conn
  • code: i64
  • why: str

Defined at line 807


h2_conn_start

Queue what an end sends first: the preface (client), our SETTINGS, and a WINDOW_UPDATE that opens the connection window.

pub fn h2_conn_start(c: & mut H2Conn) {

Parameters:

  • c: & mut H2Conn

Defined at line 867


h2_process

Handle one frame the peer sent. False when the connection is over (an error, or GOAWAY with nothing left to finish).

pub fn h2_process(c: & mut H2Conn, f: H2Frame) -> bool {

Parameters:

  • c: & mut H2Conn
  • f: H2Frame

Returns: bool

Defined at line 1133


h2_send_headers

Queue the header block of stream id as HEADERS and as many CONTINUATION frames as the peer’s frame size needs.

pub fn h2_send_headers(c: & mut H2Conn, id: i64, names: Vec<str>, vals: Vec<str>, end_stream: bool) {

Parameters:

  • c: & mut H2Conn
  • id: i64
  • names: Vec<str>
  • vals: Vec<str>
  • end_stream: bool

Defined at line 1247


h2_pump

Send what the windows allow of every stream’s pending body, a frame per stream in turn, so streams share the connection.

pub fn h2_pump(c: & mut H2Conn) {

Parameters:

  • c: & mut H2Conn

Defined at line 1289


h2_request

The request a handler gets: method and path from the pseudo-header fields, the other fields as headers (with “host” from :authority), the body. version is “2”.

pub fn h2_request(s: H2Stream) -> HttpRequest {

Parameters:

  • s: H2Stream

Returns: HttpRequest

Defined at line 1346


h2_response_fields

Turn a response of module http (build_response: “HTTP/1.1 200 OK”, headers, body) into HTTP/2 fields and a body. Text that is not such a response is sent as a 200 text/plain body.

pub fn h2_response_fields(resp: str, names: & mut Vec<str>, vals: & mut Vec<str>) -> str {

Parameters:

  • resp: str
  • names: & mut Vec<str>
  • vals: & mut Vec<str>

Returns: str

Defined at line 1388


http2_set_handler

The handler the server calls (http2_serve and http2_listen_tasks set it).

pub fn http2_set_handler(handler: fn(HttpRequest) -> str) {

Parameters:

  • handler: fn(HttpRequest) -> str

Defined at line 1446


h2_server_step

After a frame: run the handlers of complete requests, send what the windows allow, forget finished streams.

pub fn h2_server_step(c: & mut H2Conn) {

Parameters:

  • c: & mut H2Conn

Defined at line 1452


http2_serve_conn

Serve one accepted connection until it closes: the preface, then frames of any number of streams. Returns 0.

pub fn http2_serve_conn(fd: i64) -> i64 {

Parameters:

  • fd: i64

Returns: i64

Defined at line 1460


h2_conn_task

A connection’s task (task_go needs a name).

pub fn h2_conn_task(fd: i64) -> i64 {

Parameters:

  • fd: i64

Returns: i64

Defined at line 1506


h2_accept_task

Take connections off the listening socket, each its own task, until http2_stop().

pub fn h2_accept_task(fd: i64) -> i64 {

Parameters:

  • fd: i64

Returns: i64

Defined at line 1512


http2_stop

Ask the server to stop accepting; connections finish their streams.

pub fn http2_stop() {

Defined at line 1526


http2_listen_tasks

Serve a listening socket from tasks and return: they run whenever the caller waits (task_sleep, task_run, a client call).

pub fn http2_listen_tasks(fd: i64, handler: fn(HttpRequest) -> str) {

Parameters:

  • fd: i64
  • handler: fn(HttpRequest) -> str

Defined at line 1532


http2_serve

Serve HTTP/2 (h2c, prior knowledge) on port with a handler of module http, until http2_stop(). False if the port cannot be opened.

pub fn http2_serve(port: i64, handler: fn(HttpRequest) -> str) -> bool {

Parameters:

  • port: i64
  • handler: fn(HttpRequest) -> str

Returns: bool

Defined at line 1540


Http2Response

A response. status 0: no response (error says why).

pub struct Http2Response {

Fields:

NameType
statusi64
namesVec<str>
valsVec<str>
bodystr
streami64
errorstr

Defined at line 1553


http2_header

A response header (name in lowercase), "" when absent.

pub fn http2_header(r: Http2Response, name: str) -> str {

Parameters:

  • r: Http2Response
  • name: str

Returns: str

Defined at line 1569


http2_connect

Connect to host:port and start HTTP/2 with prior knowledge: the preface and our SETTINGS go out at once. ok false on failure.

pub fn http2_connect(host: str, port: i64) -> H2Conn {

Parameters:

  • host: str
  • port: i64

Returns: H2Conn

Defined at line 1582


http2_request

Open a stream with a request; returns its id (-1 if the connection cannot take one). names/vals are extra fields (lowercase names).

pub fn http2_request(c: & mut H2Conn, method: str, path: str, names: Vec<str>, vals: Vec<str>, body: str) -> i64 {

Parameters:

  • c: & mut H2Conn
  • method: str
  • path: str
  • names: Vec<str>
  • vals: Vec<str>
  • body: str

Returns: i64

Defined at line 1597


http2_wait

Read frames until stream id has its whole response, and return it (the stream is then forgotten).

pub fn http2_wait(c: & mut H2Conn, id: i64) -> Http2Response {

Parameters:

  • c: & mut H2Conn
  • id: i64

Returns: Http2Response

Defined at line 1649


http2_close

Say goodbye (GOAWAY) and close the socket.

pub fn http2_close(c: & mut H2Conn) {

Parameters:

  • c: & mut H2Conn

Defined at line 1692


http2_get

GET path from host:port over h2c with prior knowledge.

pub fn http2_get(host: str, port: i64, path: str) -> Http2Response {

Parameters:

  • host: str
  • port: i64
  • path: str

Returns: Http2Response

Defined at line 1705


http2_post

POST body to path.

pub fn http2_post(host: str, port: i64, path: str, content_type: str, body: str) -> Http2Response {

Parameters:

  • host: str
  • port: i64
  • path: str
  • content_type: str
  • body: str

Returns: Http2Response

Defined at line 1717


http2_get_many

GET every path at once on one connection (each its own stream, all sent before any response is read); the responses in the order of paths.

pub fn http2_get_many(host: str, port: i64, paths: Vec<str>) -> Vec<Http2Response> {

Parameters:

  • host: str
  • port: i64
  • paths: Vec<str>

Returns: Vec<Http2Response>

Defined at line 1734


Generated by scribe, the Fides documentation generator