|
Orbit Framework 2.0.0
A high-performance asynchronous C++20 HTTP server framework.
|
ResponseWriter implementation for HTTP/2 streams. More...
#include <Http2Session.hpp>


Public Member Functions | |
| Http2ResponseWriter (std::weak_ptr< Http2Session > session, int32_t stream_id, 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 | |
| std::shared_ptr< Http2Session > | session_or_throw () |
| void | apply_response_hooks (http::HttpResponse &response) |
Private Attributes | |
| std::weak_ptr< Http2Session > | session_ |
| int32_t | stream_id_ |
| 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 | Http2Session |
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 |
ResponseWriter implementation for HTTP/2 streams.
| orbit::http::h2::Http2ResponseWriter::Http2ResponseWriter | ( | std::weak_ptr< Http2Session > | session, |
| int32_t | stream_id, | ||
| bool | suppress_body = false |
||
| ) |
|
overridevirtual |
Adds an interceptor to modify the response before it is sent.
| interceptor | The interceptor callback. |
Implements orbit::http::ResponseWriter.
|
private |
|
overridevirtual |
Ends a chunked response stream.
Implements orbit::http::ResponseWriter.
|
overridevirtual |
Gets the underlying Proactor to dispatch async operations.
Implements orbit::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 orbit::http::ResponseWriter.
|
overridevirtual |
Sends a complete HTTP response.
Takes ownership of any file descriptors managed by the response.
| response | The HttpResponse to send. |
Implements orbit::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 orbit::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 orbit::http::ResponseWriter.
|
private |
|
overridevirtual |
Adds a default header that will be included in the final response.
| key | The header name. |
| value | The header value. |
Implements orbit::http::ResponseWriter.
|
overridevirtual |
Gets the thread pool to offload blocking tasks.
Implements orbit::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 orbit::http::ResponseWriter.
|
overridevirtual |
Streams a chunk of data (for Chunked Transfer Encoding).
| chunk | The data chunk to write. |
Implements orbit::http::ResponseWriter.
|
friend |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |