net::http2
A binary framing layer multiplexing many request/response streams over one connection, with HPACK header compression (RFC 7541) over the RFC 7540 framing.
public module net::http2::huffman;
public module net::http2::hpack;
public module net::http2::settings;
public module net::http2::frame;
public module net::http2::connection;
public module net::http2::client;
public module net::http2::server;
| File | What it holds | Import |
|---|---|---|
connection | Http2Connection<S>, one multiplexed connection either way | import std::net::http2::connection; |
client | Http2Client, connect, one_shot | import std::net::http2::client; |
server | Http2Server, serve | import std::net::http2::server; |
The framing internals — frame, hpack, huffman, settings — are public modules but have no pages: they are the wire format, driven entirely by Http2Connection, and nothing outside this module calls them.
Http2Connection<S> runs over any BufStream<S> whose transport is AsyncTransport, so the same code speaks h2c — prior-knowledge cleartext over TcpStream — and h2 over a TlsStream once ALPN has negotiated h2. It reuses Request and Response from net::http, so a handler is the same (Request) -> Response function pointer in both protocols; authority stands in for HTTP/1.1's Host, as the :authority pseudo-header requires.
public function name() { ... }
public:Visible to any module that imports this one - the default for top-level items and for struct fields, so it is mostly written to be explicit. public: opens a visibility block that groups the members after it.
public module collections::array;In a directory's _module.cryo aggregator, lists a submodule and whether it is public. Importing the directory's namespace sees only the modules declared public here.
namespace std::net::http2;net::http2: HTTP/2 (RFC 7540) with HPACK header compression (RFC 7541).
module pagenamespace std::net::http2::huffman;HPACK Huffman coding (RFC 7541 Appendix B).
namespace std::net::http2::hpack;HPACK header compression (RFC 7541).
namespace std::net::http2::settings;HTTP/2 SETTINGS parameters (RFC 7540 section 6.5).
namespace std::net::http2::frame;HTTP/2 framing (RFC 7540 section 4, section 6).
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;
}import a::b;
import a::b::{ X, Y };
import a::b as c;
import a::b::*;Brings a module, or selected items from it, into scope. One path per declaration: use the brace form for several items, as to alias, and * for everything public (prefer the brace form; wildcards invite name collisions).
type struct Http2Server {
listener: TcpListener;
}A single-connection-at-a-time h2c (cleartext) server.
std::net::http2::servertype struct BufStream<S> {
inner: S;
rbuf: Array<u8>;
rpos: u64;
scratch: Array<u8>;
wbuf: Array<u8>;
}type trait AsyncTransport {
async read_into(mut &this, buf: Array<u8>) -> Transfer;
async write_from(mut &this, buf: Array<u8>) -> Transfer;
}One raw, unbuffered async byte channel: what BufStream<S> needs of a transport, and nothing more.
type struct TcpStream {
fd: i32;
}type struct TlsStream {
ssl: void*;
inner: TcpStream;
}type struct Request {
method: Method;
path: String;
version: String;
headers: Headers;
body: Array<u8>;
params: HashMap<String, String>;
}HTTP request.
std::net::http::requesttype struct Response {
status: StatusCode;
version: String;
headers: Headers;
body: Array<u8>;
}HTTP response.
std::net::http::response