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

Server-side handle for writing an HTTP/2 response to one request. More...

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

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

Public Member Functions

absl::Status SendHeaders (int status, HttpHeaders headers={})
 Sends the response status and headers.
 
absl::Status Write (std::string data)
 Writes a chunk of response body data.
 
absl::Status Finish ()
 Signals the end of the response body.
 
absl::Status FinishWithTrailers (HttpHeaders trailers)
 Ends the response body with a trailer section.
 
absl::Status SendResponse (int status, HttpHeaders headers={}, std::string body={})
 Sends a complete response (status, headers, and body) in one call.
 
absl::StatusOr< std::shared_ptr< Http2ResponseWriter > > PushPromise (std::string method, std::string path, HttpHeaders headers={})
 Promises a response the client did not ask for (server push).
 
absl::Status Abort (absl::Status status)
 Aborts the response with the given status.
 
a11::Task Done () const
 
void DeferResponse ()
 Says this response will be sent after the handler returns.
 
bool response_deferred () const
 
bool headers_sent () const
 
bool finished () const
 
std::int32_t stream_id () const
 

Friends

class Http2Connection
 
class Http1Connection
 

Detailed Description

Server-side handle for writing an HTTP/2 response to one request.

Handed to an Http2RequestHandler. Either stream the response incrementally (SendHeaders() then Write()/Finish()) or emit it in one call with SendResponse().

Member Function Documentation

◆ Abort()

absl::Status a11::net::Http2ResponseWriter::Abort ( absl::Status  status)

Aborts the response with the given status.

◆ DeferResponse()

void a11::net::Http2ResponseWriter::DeferResponse ( )

Says this response will be sent after the handler returns.

A handler that returns without responding gets a 204, which is right for one that had nothing to say and wrong for one that handed this writer to something else: answering 204 to a WebSocket upgrade ends the stream the new owner was about to accept. Deferring suppresses that fallback, leaving the response to the owner and the timeout to the client.

◆ Done()

a11::Task a11::net::Http2ResponseWriter::Done ( ) const
Returns
An awaitable that resolves when the response is done.

◆ Finish()

absl::Status a11::net::Http2ResponseWriter::Finish ( )

Signals the end of the response body.

◆ finished()

bool a11::net::Http2ResponseWriter::finished ( ) const
Returns
Whether the response has been finished.

◆ FinishWithTrailers()

absl::Status a11::net::Http2ResponseWriter::FinishWithTrailers ( HttpHeaders  trailers)

Ends the response body with a trailer section.

Parameters
trailersFields to send after the body; an empty list makes this Finish(). Pseudo-headers are not permitted in a trailer section.

◆ headers_sent()

bool a11::net::Http2ResponseWriter::headers_sent ( ) const
Returns
Whether the response headers have been sent.

◆ PushPromise()

absl::StatusOr< std::shared_ptr< Http2ResponseWriter > > a11::net::Http2ResponseWriter::PushPromise ( std::string  method,
std::string  path,
HttpHeaders  headers = {} 
)

Promises a response the client did not ask for (server push).

Sends a PUSH_PROMISE naming the request method and path, and returns the writer for its response – driven exactly like this one. Must be called before this response is finished: HTTP/2 does not allow a promise on a stream that has already closed.

Parameters
methodMethod of the promised request; must be safe and cacheable.
pathAbsolute path, including any query.
headersHeader fields of the promised request.
Returns
The pushed response's writer, or an error – FailedPrecondition when the client did not enable push, or when this response has already finished.

◆ response_deferred()

bool a11::net::Http2ResponseWriter::response_deferred ( ) const
Returns
Whether DeferResponse() was called.

◆ SendHeaders()

absl::Status a11::net::Http2ResponseWriter::SendHeaders ( int  status,
HttpHeaders  headers = {} 
)

Sends the response status and headers.

◆ SendResponse()

absl::Status a11::net::Http2ResponseWriter::SendResponse ( int  status,
HttpHeaders  headers = {},
std::string  body = {} 
)

Sends a complete response (status, headers, and body) in one call.

◆ stream_id()

std::int32_t a11::net::Http2ResponseWriter::stream_id ( ) const
inline
Returns
The HTTP/2 stream identifier.

◆ Write()

absl::Status a11::net::Http2ResponseWriter::Write ( std::string  data)

Writes a chunk of response body data.

Friends And Related Symbol Documentation

◆ Http1Connection

friend class Http1Connection
friend

◆ Http2Connection

friend class Http2Connection
friend

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