39 virtual void set_header(
const std::string& key,
const std::string& value) = 0;
76 virtual void end() = 0;
84 virtual void send_sse_event(std::string_view data, std::string_view event =
"", std::string_view
id =
"") = 0;
98 virtual void read_body_stream(std::function<
void(std::string_view)> on_data, std::function<
void()> on_end) = 0;
116 using ErrorSink = std::function<void(std::exception_ptr, std::shared_ptr<ResponseWriter>)>;
136 std::exception_ptr error)
noexcept;
Definition ThreadPool.hpp:13
Represents an HTTP response to be sent to a client.
Definition HttpResponse.hpp:107
Abstract interface for writing HTTP responses.
Definition ResponseWriter.hpp:23
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.
std::mutex close_mutex_
Definition ResponseWriter.hpp:179
std::atomic< bool > closed_
Definition ResponseWriter.hpp:178
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.
std::atomic< bool > responded_
Definition ResponseWriter.hpp:174
std::vector< std::function< void()> > close_callbacks_
Definition ResponseWriter.hpp:180
virtual void write_chunk(std::string_view chunk)=0
Streams a chunk of data (for Chunked Transfer Encoding).
void mark_responded()
Implementations call this whenever they write part of a response.
Definition ResponseWriter.hpp:160
virtual ~ResponseWriter()=default
void set_error_sink(ErrorSink sink)
Definition ResponseWriter.hpp:117
virtual void send_headers(HttpResponse &response)=0
Sends only the HTTP headers.
std::function< void(std::exception_ptr, std::shared_ptr< ResponseWriter >)> ErrorSink
Receives an exception that escaped asynchronous handler code, such as a coroutine handler that threw ...
Definition ResponseWriter.hpp:116
virtual concurrency::ThreadPool & thread_pool()=0
Gets the thread pool to offload blocking tasks.
void reset_responded()
Definition ResponseWriter.hpp:163
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.
ErrorSink error_sink_
Definition ResponseWriter.hpp:177
std::mutex error_sink_mutex_
Definition ResponseWriter.hpp:176
virtual void add_interceptor(Interceptor interceptor)=0
Adds an interceptor to modify the response before it is sent.
uint64_t request_generation() const
Definition ResponseWriter.hpp:125
virtual network::Proactor & proactor()=0
Gets the underlying Proactor to dispatch async operations.
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.
virtual void end()=0
Ends a chunked response stream.
void mark_closed() noexcept
void on_close(std::function< void()> callback)
Runs callback once when the writer closes (see is_open()), or right away if it already has.
std::atomic< uint64_t > generation_
Definition ResponseWriter.hpp:175
virtual void send(HttpResponse &&response)=0
Sends a complete HTTP response.
std::function< void(HttpResponse &)> Interceptor
Definition ResponseWriter.hpp:27
bool is_open() const
False once the client can no longer receive anything: the connection (HTTP/1.1) or stream (HTTP/2,...
Definition ResponseWriter.hpp:146
bool has_responded() const
True once anything of a response to the current request has been sent: a full response,...
Definition ResponseWriter.hpp:107
Definition Proactor.hpp:9
Definition Awaitable.hpp:10
Definition Http2Session.hpp:21