connection
import std::net::http2::connection; · source
Http2Connection<S>
type struct Http2Connection<S> {
conn: BufStream<S>;
encoder: HpackEncoder;
decoder: HpackDecoder;
is_client: boolean;
next_stream_id: u32;
goaway_received: boolean;
remote_max_frame: u64;
remote_initial_window: i64;
conn_send_window: i64;
stream_send_window: i64;
drop(mut &this) -> void;
static new_client(conn: BufStream<S>) -> Http2Connection<S>;
static new_server(conn: BufStream<S>) -> Http2Connection<S>;
connection(mut &this) -> BufStream<S>*;
goaway_seen(&this) -> boolean;
async handshake_client(mut &this) -> Result<(), IoError>
where S: AsyncTransport;
async handshake_server(mut &this) -> Result<(), IoError>
where S: AsyncTransport;
async await_peer_settings(mut &this) -> Result<(), IoError>
where S: AsyncTransport;
queue_settings(mut &this) -> Result<(), IoError>;
process_control(mut &this, fr: &Frame) -> Result<boolean, IoError>;
queue_header_block(mut &this, stream_id: u32, block: Slice<u8>, end_stream: boolean) -> Result<(), IoError>;
async send_body(mut &this, stream_id: u32, body: Array<u8>, end_stream: boolean) -> Result<(), IoError>
where S: AsyncTransport;
async ensure_send_window(mut &this) -> Result<(), IoError>
where S: AsyncTransport;
queue_ack_data(mut &this, stream_id: u32, n: u64) -> Result<(), IoError>;
async request(mut &this, req: Request, scheme: Str, authority: Str) -> Result<Response, IoError>
where S: AsyncTransport;
async read_response(mut &this, sid: u32) -> Result<Response, IoError>
where S: AsyncTransport;
async serve(mut &this, handler: (Request) -> Response) -> Result<(), IoError>
where S: AsyncTransport;
async read_request(mut &this) -> Result<Option<RequestOnStream>, IoError>
where S: AsyncTransport;
async send_response(mut &this, sid: u32, resp: Response) -> Result<(), IoError>
where S: AsyncTransport;
async send_goaway(mut &this, last_stream_id: u32, error_code: u32) -> Result<(), IoError>
where S: AsyncTransport;
encode_request_headers(mut &this, out: mut &Array<u8>, req: &Request, scheme: Str, authority: Str) -> void;
encode_response_headers(mut &this, out: mut &Array<u8>, resp: &Response) -> void;
encode_regular_headers(mut &this, out: mut &Array<u8>, h: &Headers) -> void;
}
One HTTP/2 connection over any async transport S — a TcpStream for h2c, a TlsStream for h2. It owns the HPACK encoder and decoder, performs the connection preface and SETTINGS handshake, and exposes request (client side) and serve (server side). Requests and responses are the same Request / Response types the HTTP/1.1 layer uses, so handlers and clients are written once.
mut conn: Http2Connection<TcpStream> = Http2Connection<TcpStream>::new_client(stream);
await conn.handshake_client()?;
const first: Response = await conn.request(req_a, Str::new("http"), authority)?;
const second: Response = await conn.request(req_b, Str::new("http"), authority)?;
It owns its BufStream<S>, as WebSocket<S> does and for the same reason: the type carries per-connection protocol state — the HPACK tables, the flow-control windows, the next stream id — and an async method may only re-address its own receiver between polls. Owning the connection is also what gives the read side one buffer for the whole connection: bytes of the next frame that arrived in the same fill as the previous one are still there to be parsed rather than lost. connection() surfaces the transport for socket options or the negotiated ALPN protocol, not for reading or writing.
The write side is synchronous throughout — the queue_* methods only append to the connection's pending buffer — so a whole HEADERS block plus its CONTINUATION fragments is assembled with no suspension point inside it, and the connection suspends exactly once, in flush.
Scope. Streams are processed sequentially within a connection — one outstanding request/response at a time, the common keep-alive pattern. Flow control is honoured in both directions for that single active stream plus the connection window; true concurrent multiplexing and server push are out of scope. goaway_seen() reports whether the peer has signalled it is done; send_goaway says so in the other direction.
Settings
const LOCAL_HEADER_TABLE_SIZE: u32 = 4096;
const LOCAL_ENABLE_PUSH: u32 = 0;
const LOCAL_INITIAL_WINDOW_SIZE: u32 = 1048576;
const LOCAL_MAX_FRAME_SIZE: u32 = 16384;
const LOCAL_MAX_HEADER_LIST_SIZE: u32 = 262144;
const LOCAL_MAX_BODY_SIZE: u64 = 16777216;
const DEFAULT_CONNECTION_WINDOW: i64 = 65535;
The values advertised in the local SETTINGS frame, and the body cap enforced on the receive side.