42 auto append(
const std::vector<uint8_t>& chunk) -> bool;
63 std::
size_t headers_end) -> std::
size_t;
95 auto get_path_param(
const std::string& name)
const -> std::optional<std::string>
97 auto it = path_params.find(name);
98 if (it != path_params.end())
144 std::map<std::string, std::string>& path_params)
const -> bool;
206 class http_server :
public std::enable_shared_from_this<http_server>
213 explicit http_server(
const std::string& server_id);
225 auto start(
unsigned short port) ->
VoidResult;
236 auto wait_for_stop() -> void;
243 auto get(
const std::string& pattern,
http_handler handler) -> void;
250 auto post(
const std::string& pattern,
http_handler handler) -> void;
257 auto put(
const std::string& pattern,
http_handler handler) -> void;
264 auto del(
const std::string& pattern,
http_handler handler) -> void;
271 auto patch(
const std::string& pattern,
http_handler handler) -> void;
278 auto head(
const std::string& pattern,
http_handler handler) -> void;
285 auto options(
const std::string& pattern,
http_handler handler) -> void;
291 auto set_not_found_handler(
http_handler handler) -> void;
310 auto set_default_error_handler(
error_handler handler) -> void;
316 auto set_request_timeout(std::chrono::milliseconds timeout) -> void;
322 auto set_json_error_responses(
bool enable) -> void;
328 auto set_compression_enabled(
bool enable) -> void;
334 auto set_compression_threshold(
size_t threshold_bytes) -> void;
344 const std::string& pattern,
355 const std::string& path,
356 std::map<std::string, std::string>& path_params)
const
364 auto handle_request(
const std::vector<uint8_t>& request_data) -> std::vector<uint8_t>;
388 auto create_error_response(
int status_code,
const std::string&
message)
397 static auto pattern_to_regex(
const std::string& pattern,
398 std::vector<std::string>& param_names) -> std::string;
413 auto choose_compression_algorithm(
const std::string& accept_encoding)
const
434 bool compression_enabled_ =
false;
435 size_t compression_threshold_ = 1024;
442 bool use_json_errors_ =
false;
443 std::chrono::milliseconds request_timeout_{30000};
HTTP/1.1 server built on top of messaging_server.
http_handler not_found_handler_
std::map< internal::http_error_code, error_handler > error_handlers_
std::mutex buffers_mutex_
error_handler default_error_handler_
std::mutex compression_mutex_
std::mutex error_handlers_mutex_
std::vector< http_route > routes_
std::map< std::shared_ptr< session::messaging_session >, http_request_buffer > session_buffers_
http_handler error_handler_
std::shared_ptr< messaging_server > tcp_server_
TCP server implementation.
std::function< internal::http_response(const http_request_context &ctx)> http_handler
Handler function for HTTP requests.
std::function< internal::http_response(const internal::http_error &error)> error_handler
Handler function for HTTP errors.
http_error_code
Standard HTTP error codes (RFC 7231)
http_method
HTTP request methods (verbs)
compression_algorithm
Supported compression algorithms.
Result< T > error(int code, const std::string &message, const std::string &source="network_system", const std::string &details="")
Network-specific error and result type definitions.
Buffer for accumulating HTTP request data received in chunks.
auto append(const std::vector< uint8_t > &chunk) -> bool
Append new data chunk to buffer.
static auto parse_content_length(const std::vector< uint8_t > &data, std::size_t headers_end) -> std::size_t
Parse Content-Length from headers.
std::vector< uint8_t > data
std::size_t content_length
auto is_complete() const -> bool
Check if complete HTTP request has been received.
static constexpr std::size_t MAX_REQUEST_SIZE
static auto find_header_end(const std::vector< uint8_t > &data) -> std::size_t
Find end of HTTP headers (\r\n\r\n marker)
static constexpr std::size_t MAX_HEADER_SIZE
std::size_t headers_end_pos
Context for an HTTP request with parsed components.
auto get_path_param(const std::string &name) const -> std::optional< std::string >
Get path parameter value.
auto get_query_param(const std::string &name) const -> std::optional< std::string >
Get query parameter value.
internal::http_request request
std::map< std::string, std::string > path_params
Route definition with pattern matching and handler.
std::vector< std::string > param_names
internal::http_method method
Structured HTTP error information.
Represents an HTTP request message.
std::map< std::string, std::string > query_params
Represents an HTTP response message.