Stdlibnet::http2
client
import std::net::http2::client; · source
Http2Client
type struct Http2Client {
static new() -> Http2Client;
async get(&this, addr: SocketAddr, authority: Str, path: Str) -> Result<Response, IoError>;
async post(&this, addr: SocketAddr, authority: Str, path: Str, content_type: Str, body: Array<u8>) -> Result<Response, IoError>;
}
async function connect<S>(conn: BufStream<S>) -> Result<Http2Connection<S>, IoError>
where S: AsyncTransport;
async function one_shot(addr: SocketAddr, authority: Str, req: Request) -> Result<Response, IoError>;
Http2Client makes one-shot h2c requests over plain TCP: get and post each dial addr, upgrade to HTTP/2 with the prior-knowledge preface, run one request/response, and close. authority becomes the :authority pseudo-header — HTTP/2's spelling of Host.
import std::net::http2::client;
mut c: Http2Client = Http2Client::new();
const resp: Response = await c.get(addr, Str::new("localhost:8080"), Str::new("/"))?;
one_shot is the same with a request you built yourself. connect is the building block underneath both: it takes ownership of an already-connected BufStream<S>, performs the client handshake, and hands back an Http2Connection to issue several requests over. Over a TlsStream whose ALPN negotiated h2, that is how you speak HTTPS/2.