|
Orbit Framework
An ultra-modern, asynchronous, cross-platform C++ Web Framework.
|
Represents an active client connection, handling request parsing and response writing. More...
#include <Connection.hpp>


Public Member Functions | |
| Connection (network::Socket socket, const std::string &client_ip, network::Proactor &proactor, const routing::Router &router, ConnectionManager &manager, concurrency::ThreadPool &thread_pool, TimerManager &timer_manager, size_t max_body_size, network::TlsContext *tls_context=nullptr) | |
| Constructs a new Connection. | |
| ~Connection () | |
| Connection (const Connection &)=delete | |
| Connection & | operator= (const Connection &)=delete |
| void | start () |
| Starts processing the connection. | |
| void | write_raw (const std::vector< char > &data) |
| Writes raw data to the connection. | |
| void | mark_for_close () |
| Marks the connection to be closed after writing completes. | |
| void | upgrade_to_websocket (std::unique_ptr< http::websocket::WebSocketConnection > ws_conn) |
| Upgrades the connection to a WebSocket. | |
| const std::string & | client_ip () const |
| Gets the client's IP address. | |
| void | add_interceptor (std::function< void(http::HttpResponse &)> interceptor) override |
| 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 http::ResponseWriter | |
| virtual | ~ResponseWriter ()=default |
| virtual void | add_interceptor (Interceptor interceptor)=0 |
| Adds an interceptor to modify the response before it is sent. | |
Additional Inherited Members | |
Public Types inherited from http::ResponseWriter | |
| using | Interceptor = std::function< void(HttpResponse &)> |
Represents an active client connection, handling request parsing and response writing.
| server::Connection::Connection | ( | network::Socket | socket, |
| const std::string & | client_ip, | ||
| network::Proactor & | proactor, | ||
| const routing::Router & | router, | ||
| ConnectionManager & | manager, | ||
| concurrency::ThreadPool & | thread_pool, | ||
| TimerManager & | timer_manager, | ||
| size_t | max_body_size, | ||
| network::TlsContext * | tls_context = nullptr |
||
| ) |
Constructs a new Connection.
| socket | The connection socket. |
| client_ip | The client's IP address. |
| proactor | The Proactor for async I/O. |
| router | The application router. |
| manager | The connection manager. |
| thread_pool | The application thread pool. |
| timer_manager | The timer manager for timeouts. |
| max_body_size | Maximum allowed request body size. |
| tls_context | The TLS context, if applicable. |
| server::Connection::~Connection | ( | ) |
|
delete |
|
override |
|
inline |
Gets the client's IP address.
|
overridevirtual |
Ends a chunked response stream.
Implements http::ResponseWriter.
| void server::Connection::mark_for_close | ( | ) |
Marks the connection to be closed after writing completes.
|
delete |
|
inlineoverridevirtual |
Gets the underlying Proactor to dispatch async operations.
Implements http::ResponseWriter.
|
overridevirtual |
Asynchronously streams the incoming HTTP request body.
| on_data | Callback invoked when a body chunk is received. |
| on_end | Callback invoked when the entire body has been read. |
Implements http::ResponseWriter.
|
overridevirtual |
Sends a complete HTTP response.
Takes ownership of any file descriptors managed by the response.
| response | The HttpResponse to send. |
Implements http::ResponseWriter.
|
overridevirtual |
Sends only the HTTP headers.
Useful for streaming bodies or Server-Sent Events.
| response | The HttpResponse containing the headers to send. |
Implements http::ResponseWriter.
|
overridevirtual |
Sends a Server-Sent Events (SSE) message.
| data | The event data payload. |
| event | The event type/name (optional). |
| id | The event ID (optional). |
Implements http::ResponseWriter.
|
overridevirtual |
Adds a default header that will be included in the final response.
| key | The header name. |
| value | The header value. |
Implements http::ResponseWriter.
| void server::Connection::start | ( | ) |
Starts processing the connection.
|
inlineoverridevirtual |
Gets the thread pool to offload blocking tasks.
Implements http::ResponseWriter.
|
overridevirtual |
Upgrades the connection to a raw bi-directional byte stream.
| on_data | Callback invoked when data is received. |
| on_close | Callback invoked when the stream is closed. |
Implements http::ResponseWriter.
| void server::Connection::upgrade_to_websocket | ( | std::unique_ptr< http::websocket::WebSocketConnection > | ws_conn | ) |
Upgrades the connection to a WebSocket.
| ws_conn | The WebSocket connection instance. |
|
overridevirtual |
Streams a chunk of data (for Chunked Transfer Encoding).
| chunk | The data chunk to write. |
Implements http::ResponseWriter.
| void server::Connection::write_raw | ( | const std::vector< char > & | data | ) |
Writes raw data to the connection.
| data | The raw data to write. |