Orbit Framework
An ultra-modern, asynchronous, cross-platform C++ Web Framework.
Loading...
Searching...
No Matches
ResponseWriter.hpp
Go to the documentation of this file.
1#pragma once
3#include <string_view>
4#include <memory>
5#include <orbit/http/json.hpp>
6
7namespace network { class Proactor; }
8namespace concurrency { class ThreadPool; }
9
10namespace http {
11
17public:
18 virtual ~ResponseWriter() = default;
19
20 using Interceptor = std::function<void(HttpResponse&)>;
25 virtual void add_interceptor(Interceptor interceptor) = 0;
26
32 virtual void set_header(const std::string& key, const std::string& value) = 0;
33
39
45
51 virtual void send(HttpResponse&& response) = 0;
52
58 virtual void send_headers(HttpResponse& response) = 0;
59
64 virtual void write_chunk(std::string_view chunk) = 0;
65
69 virtual void end() = 0;
70
77 virtual void send_sse_event(std::string_view data, std::string_view event = "", std::string_view id = "") = 0;
78
84 virtual void upgrade_to_raw_stream(std::function<void(std::string_view)> on_data, std::function<void()> on_close) = 0;
85
91 virtual void read_body_stream(std::function<void(std::string_view)> on_data, std::function<void()> on_end) = 0;
92};
93
94} // namespace http
Definition ThreadPool.hpp:12
Represents an HTTP response to be sent to a client.
Definition HttpResponse.hpp:50
Abstract interface for writing HTTP responses.
Definition ResponseWriter.hpp:16
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 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 send_headers(HttpResponse &response)=0
Sends only the HTTP headers.
virtual void end()=0
Ends a chunked response stream.
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 ~ResponseWriter()=default
virtual void write_chunk(std::string_view chunk)=0
Streams a chunk of data (for Chunked Transfer Encoding).
virtual void send(HttpResponse &&response)=0
Sends a complete HTTP response.
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.
std::function< void(HttpResponse &)> Interceptor
Definition ResponseWriter.hpp:20
virtual concurrency::ThreadPool & thread_pool()=0
Gets the thread pool to offload blocking tasks.
Definition Proactor.hpp:8
Definition Task.hpp:5
Definition Http2Session.hpp:21
Definition ResponseWriter.hpp:7