Orbit Framework 2.0.0
A high-performance asynchronous C++20 HTTP server framework.
Loading...
Searching...
No Matches
orbit::server::Http3ResponseWriter Class Reference

ResponseWriter for HTTP/3 streams. More...

#include <QuicHttp3Session.hpp>

Inheritance diagram for orbit::server::Http3ResponseWriter:
Collaboration diagram for orbit::server::Http3ResponseWriter:

Public Member Functions

 Http3ResponseWriter (std::weak_ptr< QuicConnection > conn, int64_t stream_id, network::Proactor &proactor, concurrency::ThreadPool &thread_pool, bool suppress_body=false)
 
void add_interceptor (Interceptor interceptor) override
 Adds an interceptor to modify the response before it is sent.
 
void set_header (const std::string &key, const std::string &value) override
 Adds a default header that will be included in the final response.
 
network::Proactor & proactor () override
 Gets the underlying Proactor to dispatch async operations.
 
concurrency::ThreadPool & thread_pool () override
 Gets the thread pool to offload blocking tasks.
 
void send (http::HttpResponse &&response) override
 Sends a complete HTTP response.
 
void send_headers (http::HttpResponse &response) override
 Sends only the HTTP headers.
 
void write_chunk (std::string_view chunk) override
 Streams a chunk of data (for Chunked Transfer Encoding).
 
void end () override
 Ends a chunked response stream.
 
void send_sse_event (std::string_view data, std::string_view event="", std::string_view id="") override
 Sends a Server-Sent Events (SSE) message.
 
void upgrade_to_raw_stream (std::function< void(std::string_view)> on_data, std::function< void()> on_close) override
 Upgrades the connection to a raw bi-directional byte stream.
 
void read_body_stream (std::function< void(std::string_view)> on_data, std::function< void()> on_end) override
 Asynchronously streams the incoming HTTP request body.
 
- Public Member Functions inherited from orbit::http::ResponseWriter
virtual ~ResponseWriter ()=default
 
bool has_responded () const
 True once anything of a response to the current request has been sent: a full response, its headers, a chunk or an event.
 
void set_error_sink (ErrorSink sink)
 
uint64_t request_generation () const
 
bool is_open () const
 False once the client can no longer receive anything: the connection (HTTP/1.1) or stream (HTTP/2, HTTP/3) closed, because the client left, a timeout fired or the server shut down.
 
void on_close (std::function< void()> callback)
 Runs callback once when the writer closes (see is_open()), or right away if it already has.
 

Private Member Functions

void apply_response_hooks (http::HttpResponse &response)
 
template<typename Fn >
void with_session (Fn &&fn)
 Runs fn on the session with the connection locked, then flushes.
 

Private Attributes

std::weak_ptr< QuicConnection > conn_
 
int64_t stream_id_
 
network::Proactor & proactor_
 
concurrency::ThreadPool & thread_pool_
 
std::unordered_map< std::string, std::string > default_headers_
 
std::vector< Interceptor > interceptors_
 
bool headers_sent_ {false}
 
bool suppress_body_ {false}
 
std::shared_ptr< void > body_owner_
 
std::string_view body_
 

Friends

class QuicHttp3Session
 

Additional Inherited Members

- Public Types inherited from orbit::http::ResponseWriter
using Interceptor = std::function< void(HttpResponse &)>
 
using ErrorSink = std::function< void(std::exception_ptr, std::shared_ptr< ResponseWriter >)>
 Receives an exception that escaped asynchronous handler code, such as a coroutine handler that threw after a co_await.
 
- Static Public Member Functions inherited from orbit::http::ResponseWriter
static void report_async_exception (const std::shared_ptr< ResponseWriter > &writer, uint64_t generation, std::exception_ptr error) noexcept
 Reports an exception from asynchronous handler code.
 
- Protected Member Functions inherited from orbit::http::ResponseWriter
void mark_responded ()
 Implementations call this whenever they write part of a response.
 
void reset_responded ()
 
void mark_closed () noexcept
 

Detailed Description

ResponseWriter for HTTP/3 streams.

Handlers run on the thread pool and may finish after the client has gone, so the writer refers to its connection only weakly.

Constructor & Destructor Documentation

◆ Http3ResponseWriter()

orbit::server::Http3ResponseWriter::Http3ResponseWriter ( std::weak_ptr< QuicConnection >  conn,
int64_t  stream_id,
network::Proactor &  proactor,
concurrency::ThreadPool &  thread_pool,
bool  suppress_body = false 
)

Member Function Documentation

◆ add_interceptor()

void orbit::server::Http3ResponseWriter::add_interceptor ( Interceptor  interceptor)
overridevirtual

Adds an interceptor to modify the response before it is sent.

Parameters
interceptorThe interceptor callback.

Implements orbit::http::ResponseWriter.

◆ apply_response_hooks()

void orbit::server::Http3ResponseWriter::apply_response_hooks ( http::HttpResponse &  response)
private

◆ end()

void orbit::server::Http3ResponseWriter::end ( )
overridevirtual

Ends a chunked response stream.

Implements orbit::http::ResponseWriter.

◆ proactor()

network::Proactor & orbit::server::Http3ResponseWriter::proactor ( )
inlineoverridevirtual

Gets the underlying Proactor to dispatch async operations.

Returns
A reference to the network::Proactor.

Implements orbit::http::ResponseWriter.

◆ read_body_stream()

void orbit::server::Http3ResponseWriter::read_body_stream ( std::function< void(std::string_view)>  on_data,
std::function< void()>  on_end 
)
overridevirtual

Asynchronously streams the incoming HTTP request body.

Parameters
on_dataCallback invoked when a body chunk is received.
on_endCallback invoked when the entire body has been read.

Implements orbit::http::ResponseWriter.

◆ send()

void orbit::server::Http3ResponseWriter::send ( http::HttpResponse &&  response)
overridevirtual

Sends a complete HTTP response.

Takes ownership of any file descriptors managed by the response.

Parameters
responseThe HttpResponse to send.

Implements orbit::http::ResponseWriter.

◆ send_headers()

void orbit::server::Http3ResponseWriter::send_headers ( http::HttpResponse &  response)
overridevirtual

Sends only the HTTP headers.

Useful for streaming bodies or Server-Sent Events.

Parameters
responseThe HttpResponse containing the headers to send.

Implements orbit::http::ResponseWriter.

◆ send_sse_event()

void orbit::server::Http3ResponseWriter::send_sse_event ( std::string_view  data,
std::string_view  event = "",
std::string_view  id = "" 
)
overridevirtual

Sends a Server-Sent Events (SSE) message.

Parameters
dataThe event data payload.
eventThe event type/name (optional).
idThe event ID (optional).

Implements orbit::http::ResponseWriter.

◆ set_header()

void orbit::server::Http3ResponseWriter::set_header ( const std::string &  key,
const std::string &  value 
)
overridevirtual

Adds a default header that will be included in the final response.

Parameters
keyThe header name.
valueThe header value.

Implements orbit::http::ResponseWriter.

◆ thread_pool()

concurrency::ThreadPool & orbit::server::Http3ResponseWriter::thread_pool ( )
inlineoverridevirtual

Gets the thread pool to offload blocking tasks.

Returns
A reference to the concurrency::ThreadPool.

Implements orbit::http::ResponseWriter.

◆ upgrade_to_raw_stream()

void orbit::server::Http3ResponseWriter::upgrade_to_raw_stream ( std::function< void(std::string_view)>  on_data,
std::function< void()>  on_close 
)
overridevirtual

Upgrades the connection to a raw bi-directional byte stream.

Parameters
on_dataCallback invoked when data is received.
on_closeCallback invoked when the stream is closed.

Implements orbit::http::ResponseWriter.

◆ with_session()

template<typename Fn >
void orbit::server::Http3ResponseWriter::with_session ( Fn &&  fn)
private

Runs fn on the session with the connection locked, then flushes.

◆ write_chunk()

void orbit::server::Http3ResponseWriter::write_chunk ( std::string_view  chunk)
overridevirtual

Streams a chunk of data (for Chunked Transfer Encoding).

Parameters
chunkThe data chunk to write.

Implements orbit::http::ResponseWriter.

Friends And Related Symbol Documentation

◆ QuicHttp3Session

friend class QuicHttp3Session
friend

Member Data Documentation

◆ body_

std::string_view orbit::server::Http3ResponseWriter::body_
private

◆ body_owner_

std::shared_ptr<void> orbit::server::Http3ResponseWriter::body_owner_
private

◆ conn_

std::weak_ptr<QuicConnection> orbit::server::Http3ResponseWriter::conn_
private

◆ default_headers_

std::unordered_map<std::string, std::string> orbit::server::Http3ResponseWriter::default_headers_
private

◆ headers_sent_

bool orbit::server::Http3ResponseWriter::headers_sent_ {false}
private

◆ interceptors_

std::vector<Interceptor> orbit::server::Http3ResponseWriter::interceptors_
private

◆ proactor_

network::Proactor& orbit::server::Http3ResponseWriter::proactor_
private

◆ stream_id_

int64_t orbit::server::Http3ResponseWriter::stream_id_
private

◆ suppress_body_

bool orbit::server::Http3ResponseWriter::suppress_body_ {false}
private

◆ thread_pool_

concurrency::ThreadPool& orbit::server::Http3ResponseWriter::thread_pool_
private

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