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

Abstract interface for writing HTTP responses. More...

#include <ResponseWriter.hpp>

Inheritance diagram for http::ResponseWriter:

Public Types

using Interceptor = std::function< void(HttpResponse &)>
 

Public Member Functions

virtual ~ResponseWriter ()=default
 
virtual void add_interceptor (Interceptor interceptor)=0
 Adds an interceptor to modify the response before it is sent.
 
virtual void set_header (const std::string &key, const std::string &value)=0
 Adds a default header that will be included in the final response.
 
virtual network::Proactorproactor ()=0
 Gets the underlying Proactor to dispatch async operations.
 
virtual concurrency::ThreadPoolthread_pool ()=0
 Gets the thread pool to offload blocking tasks.
 
virtual void send (HttpResponse &&response)=0
 Sends a complete HTTP response.
 
virtual void send_headers (HttpResponse &response)=0
 Sends only the HTTP headers.
 
virtual void write_chunk (std::string_view chunk)=0
 Streams a chunk of data (for Chunked Transfer Encoding).
 
virtual void end ()=0
 Ends a chunked response stream.
 
virtual void send_sse_event (std::string_view data, std::string_view event="", std::string_view id="")=0
 Sends a Server-Sent Events (SSE) message.
 
virtual void upgrade_to_raw_stream (std::function< void(std::string_view)> on_data, std::function< void()> on_close)=0
 Upgrades the connection to a raw bi-directional byte stream.
 
virtual void read_body_stream (std::function< void(std::string_view)> on_data, std::function< void()> on_end)=0
 Asynchronously streams the incoming HTTP request body.
 

Detailed Description

Abstract interface for writing HTTP responses.

This is used by middlewares and route handlers to write data back to the client.

Member Typedef Documentation

◆ Interceptor

using http::ResponseWriter::Interceptor = std::function<void(HttpResponse&)>

Constructor & Destructor Documentation

◆ ~ResponseWriter()

virtual http::ResponseWriter::~ResponseWriter ( )
virtualdefault

Member Function Documentation

◆ add_interceptor()

virtual void http::ResponseWriter::add_interceptor ( Interceptor  interceptor)
pure virtual

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

Parameters
interceptorThe interceptor callback.

Implemented in http::h2::Http2ResponseWriter.

◆ end()

virtual void http::ResponseWriter::end ( )
pure virtual

Ends a chunked response stream.

Implemented in http::h2::Http2ResponseWriter, and server::Connection.

◆ proactor()

virtual network::Proactor & http::ResponseWriter::proactor ( )
pure virtual

Gets the underlying Proactor to dispatch async operations.

Returns
A reference to the network::Proactor.

Implemented in http::h2::Http2ResponseWriter, and server::Connection.

◆ read_body_stream()

virtual void http::ResponseWriter::read_body_stream ( std::function< void(std::string_view)>  on_data,
std::function< void()>  on_end 
)
pure virtual

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.

Implemented in http::h2::Http2ResponseWriter, and server::Connection.

◆ send()

virtual void http::ResponseWriter::send ( HttpResponse &&  response)
pure virtual

Sends a complete HTTP response.

Takes ownership of any file descriptors managed by the response.

Parameters
responseThe HttpResponse to send.

Implemented in http::h2::Http2ResponseWriter, and server::Connection.

◆ send_headers()

virtual void http::ResponseWriter::send_headers ( HttpResponse response)
pure virtual

Sends only the HTTP headers.

Useful for streaming bodies or Server-Sent Events.

Parameters
responseThe HttpResponse containing the headers to send.

Implemented in http::h2::Http2ResponseWriter, and server::Connection.

◆ send_sse_event()

virtual void http::ResponseWriter::send_sse_event ( std::string_view  data,
std::string_view  event = "",
std::string_view  id = "" 
)
pure virtual

Sends a Server-Sent Events (SSE) message.

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

Implemented in http::h2::Http2ResponseWriter, and server::Connection.

◆ set_header()

virtual void http::ResponseWriter::set_header ( const std::string &  key,
const std::string &  value 
)
pure virtual

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

Parameters
keyThe header name.
valueThe header value.

Implemented in http::h2::Http2ResponseWriter, and server::Connection.

◆ thread_pool()

virtual concurrency::ThreadPool & http::ResponseWriter::thread_pool ( )
pure virtual

Gets the thread pool to offload blocking tasks.

Returns
A reference to the concurrency::ThreadPool.

Implemented in http::h2::Http2ResponseWriter, and server::Connection.

◆ upgrade_to_raw_stream()

virtual void http::ResponseWriter::upgrade_to_raw_stream ( std::function< void(std::string_view)>  on_data,
std::function< void()>  on_close 
)
pure virtual

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.

Implemented in http::h2::Http2ResponseWriter, and server::Connection.

◆ write_chunk()

virtual void http::ResponseWriter::write_chunk ( std::string_view  chunk)
pure virtual

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

Parameters
chunkThe data chunk to write.

Implemented in http::h2::Http2ResponseWriter, and server::Connection.


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