A11 (C++ runtime)
Native C++ implementation of the A11 streaming action runtime
Loading...
Searching...
No Matches
a11::net::Http2Client Class Reference

An HTTP/2 client connection, reusable across many streams. More...

#include <cpp/a11/net/http2.h>

Inheritance diagram for a11::net::Http2Client:
[legend]

Classes

struct  Impl
 

Public Member Functions

 ~Http2Client ()
 
absl::StatusOr< std::shared_ptr< Http2ResponseStream > > RequestStream (std::string method, std::string path, HttpHeaders headers={}, std::string body={}, std::string scheme={})
 Opens a request and returns a pull-oriented response body stream.
 
absl::StatusOr< std::shared_ptr< Http2DuplexStream > > ExtendedConnect (std::string protocol, std::string path, HttpHeaders headers={}, std::string scheme={})
 Opens an extended CONNECT duplex stream for bidirectional data.
 
absl::StatusOr< std::shared_ptr< Http2DuplexStream > > RequestStreamingBody (std::string method, std::string path, HttpHeaders headers={}, std::string scheme={})
 Opens a request whose body is written incrementally.
 
a11::Future< HttpResponse > Request (std::string method, std::string path, HttpHeaders headers={}, std::string body={}, std::string scheme={})
 
absl::Status Close ()
 Closes the client connection.
 
std::string host () const
 
std::uint16_t port () const
 
bool connected () const
 
bool secure () const
 
bool multiplexed () const
 Whether this connection can carry several exchanges at once.
 
void *absl_nullable GetImpl () const
 

Static Public Member Functions

static a11::Future< std::shared_ptr< Http2Client > > Connect (std::string host, std::uint16_t port, const Http2Options &options={})
 Asynchronously connects to an HTTP/2 server.
 

Detailed Description

An HTTP/2 client connection, reusable across many streams.

Issues buffered requests, incremental response streams, or extended CONNECT duplex streams over a single connection. Shared as the transport backing HTTP SSE and WebSocket client wire streams.

Constructor & Destructor Documentation

◆ ~Http2Client()

a11::net::Http2Client::~Http2Client ( )

Member Function Documentation

◆ Close()

absl::Status a11::net::Http2Client::Close ( )

Closes the client connection.

◆ Connect()

a11::Future< std::shared_ptr< Http2Client > > a11::net::Http2Client::Connect ( std::string  host,
std::uint16_t  port,
const Http2Options &  options = {} 
)
static

Asynchronously connects to an HTTP/2 server.

Parameters
hostServer hostname.
portServer port.
optionsBody limits, buffering, deadline, and TLS settings.
Returns
An awaitable that resolves to the connected client.

◆ connected()

bool a11::net::Http2Client::connected ( ) const
Returns
Whether the client is currently connected.

◆ ExtendedConnect()

absl::StatusOr< std::shared_ptr< Http2DuplexStream > > a11::net::Http2Client::ExtendedConnect ( std::string  protocol,
std::string  path,
HttpHeaders  headers = {},
std::string  scheme = {} 
)

Opens an extended CONNECT duplex stream for bidirectional data.

◆ GetImpl()

void *absl_nullable a11::net::Http2Client::GetImpl ( ) const
Returns
An opaque native handle for advanced interop, or nullptr.

◆ host()

std::string a11::net::Http2Client::host ( ) const
Returns
The host the client is connected to.

◆ multiplexed()

bool a11::net::Http2Client::multiplexed ( ) const

Whether this connection can carry several exchanges at once.

True for HTTP/2 (h2 or h2c), false for HTTP/1.1 – which A11 restricts to one request per connection rather than pipelining. A caller sharing a connection between requests has to know which it got.

◆ port()

std::uint16_t a11::net::Http2Client::port ( ) const
Returns
The port the client is connected to.

◆ Request()

a11::Future< HttpResponse > a11::net::Http2Client::Request ( std::string  method,
std::string  path,
HttpHeaders  headers = {},
std::string  body = {},
std::string  scheme = {} 
)
Returns
An awaitable resolving to the fully buffered response.

◆ RequestStream()

absl::StatusOr< std::shared_ptr< Http2ResponseStream > > a11::net::Http2Client::RequestStream ( std::string  method,
std::string  path,
HttpHeaders  headers = {},
std::string  body = {},
std::string  scheme = {} 
)

Opens a request and returns a pull-oriented response body stream.

◆ RequestStreamingBody()

absl::StatusOr< std::shared_ptr< Http2DuplexStream > > a11::net::Http2Client::RequestStreamingBody ( std::string  method,
std::string  path,
HttpHeaders  headers = {},
std::string  scheme = {} 
)

Opens a request whose body is written incrementally.

Where RequestStream() wants the whole body up front, this returns while the request side is still open. Http2DuplexStream::Write() sends more data and Finish() ends the body, while the same handle provides the response. This supports uploads of unknown or unbounded length without content-length: HTTP/2 uses DATA frames and HTTP/1.1 uses a chunked body.

Parameters
methodRequest method.
pathAbsolute request path, including any query.
headersRequest headers. Do not set content-length: the body's length is not known when the headers are sent.
schemeRequest scheme; defaults to the connection's.
Returns
The duplex stream, or an error.

◆ secure()

bool a11::net::Http2Client::secure ( ) const
Returns
Whether the connection is using TLS.

The documentation for this class was generated from the following files: