15namespace http::h2 {
class Http2Session; }
19class ConnectionManager;
69 void write_raw(
const std::vector<char>& data);
86 const std::string&
client_ip()
const {
return client_ip_; }
90 void set_header(
const std::string& key,
const std::string& value)
override;
97 void send_sse_event(std::string_view data, std::string_view event =
"", std::string_view
id =
"")
override;
98 void upgrade_to_raw_stream(std::function<
void(std::string_view)> on_data, std::function<
void()> on_close)
override;
99 void read_body_stream(std::function<
void(std::string_view)> on_data, std::function<
void()> on_end)
override;
102 void process_request();
103 void send_data(std::string_view data);
108 void on_read_complete(ssize_t bytes_read);
109 void trigger_write();
110 void on_write_complete(ssize_t bytes_written);
111 void on_sendfile_complete(ssize_t bytes_written);
112 void process_streaming_data();
115 std::string client_ip_;
122 std::vector<char> read_buffer_;
123 mutable std::mutex read_mutex_;
124 std::vector<char> write_buffer_;
125 std::vector<char> active_write_buffer_;
126 mutable std::mutex write_mutex_;
128 char async_read_buf_[16384];
130 std::unordered_map<std::string, std::string> default_headers_;
131 std::string current_request_buffer_;
132 std::atomic<bool> is_reading_{
false};
133 std::atomic<bool> is_writing_{
false};
134 bool is_chunked_{
false};
135 bool is_chunk_header_mode_{
true};
136 size_t chunk_bytes_remaining_{0};
137 size_t content_length_remaining_{0};
140 bool should_close_{
false};
142 uint64_t current_timer_id_{0};
146 off_t file_offset_{0};
148 size_t max_body_size_;
153 bool is_tls_handshake_complete_{
false};
154 std::vector<char> tls_write_buffer_;
156 std::atomic<bool> is_processing_request_{
false};
158 std::unique_ptr<http::websocket::WebSocketConnection> ws_connection_;
159 std::shared_ptr<http::h2::Http2Session> h2_session_;
160 std::function<void(std::string_view)> raw_stream_on_data_;
161 std::function<void()> raw_stream_on_close_;
162 std::function<void(std::string_view)> body_stream_on_data_;
163 std::function<void()> body_stream_on_end_;
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
Definition Proactor.hpp:8
Definition TlsContext.hpp:10
Manages routing of HTTP requests to their appropriate handlers.
Definition Router.hpp:30
Manages active HTTP connections.
Definition ConnectionManager.hpp:17
Represents an active client connection, handling request parsing and response writing.
Definition Connection.hpp:40
const std::string & client_ip() const
Gets the client's IP address.
Definition Connection.hpp:86
void add_interceptor(std::function< void(http::HttpResponse &)> interceptor) override
Definition Connection.cpp:379
~Connection()
Definition Connection.cpp:38
concurrency::ThreadPool & thread_pool() override
Gets the thread pool to offload blocking tasks.
Definition Connection.hpp:92
Connection(const Connection &)=delete
void set_header(const std::string &key, const std::string &value) override
Adds a default header that will be included in the final response.
Definition Connection.cpp:374
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.
Definition Connection.cpp:696
Connection & operator=(const Connection &)=delete
void send_headers(http::HttpResponse &response) override
Sends only the HTTP headers.
Definition Connection.cpp:384
void send_sse_event(std::string_view data, std::string_view event="", std::string_view id="") override
Sends a Server-Sent Events (SSE) message.
Definition Connection.cpp:517
network::Proactor & proactor() override
Gets the underlying Proactor to dispatch async operations.
Definition Connection.hpp:91
void upgrade_to_websocket(std::unique_ptr< http::websocket::WebSocketConnection > ws_conn)
Upgrades the connection to a WebSocket.
Definition Connection.cpp:691
void write_chunk(std::string_view chunk) override
Streams a chunk of data (for Chunked Transfer Encoding).
Definition Connection.cpp:472
void end() override
Ends a chunked response stream.
Definition Connection.cpp:486
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.
Definition Connection.cpp:711
void start()
Starts processing the connection.
Definition Connection.cpp:57
void mark_for_close()
Marks the connection to be closed after writing completes.
Definition Connection.cpp:686
void send(http::HttpResponse &&response) override
Sends a complete HTTP response.
Definition Connection.cpp:409
void write_raw(const std::vector< char > &data)
Writes raw data to the connection.
Definition Connection.cpp:678
Manages timers for connection timeouts.
Definition TimerManager.hpp:29
Definition Http2Session.hpp:22
Definition WebSocket.hpp:7
HttpStatus
Standard HTTP status codes.
Definition HttpResponse.hpp:14
Definition Http2Session.hpp:17
RequestState
Definition Connection.hpp:29
@ ERROR_HEADERS_TOO_LARGE
@ ERROR_PAYLOAD_TOO_LARGE
ConnectionState
Definition Connection.hpp:21