server
import std::net::http2::server; · source
Http2Server
type struct Http2Server {
listener: TcpListener;
static bind(addr: SocketAddr) -> Result<Http2Server, IoError>;
local_addr(&this) -> Result<SocketAddr, IoError>;
async serve_one(mut &this, handler: (Request) -> Response) -> Result<(), IoError>;
async run(mut &this, handler: (Request) -> Response) -> Result<(), IoError>;
async accept_one(mut &this) -> Result<TcpStream, IoError>;
drop(mut &this) -> void;
}
async function serve<S>(conn: BufStream<S>, handler: (Request) -> Response) -> Result<(), IoError>
where S: AsyncTransport;
A single-connection-at-a-time h2c server. bind(addr) opens the listener; serve_one(handler) accepts one connection and serves it until the peer closes or sends GOAWAY; run(handler) does that in a loop. The handler is the same (Request) -> Response function pointer the HTTP/1.1 server takes, so a service can offer both protocols from one set of handlers.
serve is the building block: it takes ownership of an already-connected BufStream<S>, performs the server handshake, and dispatches each request on the connection to handler. Over a TlsStream whose ALPN negotiated h2, that is how you serve HTTPS/2 — accept with a TlsAcceptor built with_alpn_h2, check negotiated_alpn(), and route to serve or to the HTTP/1.1 serve_connection accordingly.
Http2Server closes its listener through an inherent drop.