Orbit Framework
An ultra-modern, asynchronous, cross-platform C++ Web Framework.
Loading...
Searching...
No Matches
http::h2::Http2ResponseWriter Class Reference

ResponseWriter implementation for HTTP/2 streams. More...

#include <Http2Session.hpp>

Inheritance diagram for http::h2::Http2ResponseWriter:
Collaboration diagram for http::h2::Http2ResponseWriter:

Public Member Functions

 Http2ResponseWriter (Http2Session *session, int32_t stream_id)
 
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::Proactorproactor () override
 Gets the underlying Proactor to dispatch async operations.
 
concurrency::ThreadPoolthread_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 http::ResponseWriter
virtual ~ResponseWriter ()=default
 

Additional Inherited Members

- Public Types inherited from http::ResponseWriter
using Interceptor = std::function< void(HttpResponse &)>
 

Detailed Description

ResponseWriter implementation for HTTP/2 streams.

Constructor & Destructor Documentation

◆ Http2ResponseWriter()

http::h2::Http2ResponseWriter::Http2ResponseWriter ( Http2Session session,
int32_t  stream_id 
)

Member Function Documentation

◆ add_interceptor()

void http::h2::Http2ResponseWriter::add_interceptor ( Interceptor  interceptor)
overridevirtual

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

Parameters
interceptorThe interceptor callback.

Implements http::ResponseWriter.

◆ end()

void http::h2::Http2ResponseWriter::end ( )
overridevirtual

Ends a chunked response stream.

Implements http::ResponseWriter.

◆ proactor()

network::Proactor & http::h2::Http2ResponseWriter::proactor ( )
overridevirtual

Gets the underlying Proactor to dispatch async operations.

Returns
A reference to the network::Proactor.

Implements http::ResponseWriter.

◆ read_body_stream()

void http::h2::Http2ResponseWriter::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 http::ResponseWriter.

◆ send()

void http::h2::Http2ResponseWriter::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 http::ResponseWriter.

◆ send_headers()

void http::h2::Http2ResponseWriter::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 http::ResponseWriter.

◆ send_sse_event()

void http::h2::Http2ResponseWriter::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 http::ResponseWriter.

◆ set_header()

void http::h2::Http2ResponseWriter::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 http::ResponseWriter.

◆ thread_pool()

concurrency::ThreadPool & http::h2::Http2ResponseWriter::thread_pool ( )
overridevirtual

Gets the thread pool to offload blocking tasks.

Returns
A reference to the concurrency::ThreadPool.

Implements http::ResponseWriter.

◆ upgrade_to_raw_stream()

void http::h2::Http2ResponseWriter::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 http::ResponseWriter.

◆ write_chunk()

void http::h2::Http2ResponseWriter::write_chunk ( std::string_view  chunk)
overridevirtual

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

Parameters
chunkThe data chunk to write.

Implements http::ResponseWriter.


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