diff --git a/src/http_handler.cpp b/src/http_handler.cpp index 62a971b..3489231 100644 --- a/src/http_handler.cpp +++ b/src/http_handler.cpp @@ -26,6 +26,8 @@ thread_local auto version_counter = requests_counter_family.create({{"path", "/v1/version"}}); thread_local auto ok_counter = requests_counter_family.create({{"path", "/ok"}}); +thread_local auto not_found_counter = + requests_counter_family.create({{"path", "not_found"}}); HttpConnectionState::HttpConnectionState() { llhttp_settings_init(&settings); @@ -46,7 +48,8 @@ HttpConnectionState::HttpConnectionState() { // HttpConnectionState implementation HttpRequestState::HttpRequestState() - : current_header_field_buf(ArenaStlAllocator(&arena)), + : url(ArenaStlAllocator(&arena)), + current_header_field_buf(ArenaStlAllocator(&arena)), current_header_value_buf(ArenaStlAllocator(&arena)) {} // HttpHandler implementation @@ -119,8 +122,6 @@ void HttpHandler::on_batch_complete(std::span batch) { ctx->http_request_id = req.http_request_id; ctx->connection_close = req.connection_close; - char *url_buffer = req.arena.allocate(req.url.size()); - std::memcpy(url_buffer, req.url.data(), req.url.size()); RouteMatch route_match; auto parse_result = ApiUrlParser::parse(req.method, const_cast(req.url.data()), @@ -484,6 +485,7 @@ void HttpHandler::handle_get_ok(Connection &, HttpRequestState &) { } void HttpHandler::handle_not_found(Connection &conn, HttpRequestState &state) { + not_found_counter.inc(); auto json_response = R"({"error":"Not found"})"; auto http_response = format_json_response(404, json_response, state.arena, @@ -574,8 +576,8 @@ std::span HttpHandler::format_json_response( // llhttp callbacks int HttpHandler::onUrl(llhttp_t *parser, const char *at, size_t length) { auto *state = static_cast(parser->data); - // Store URL in arena (simplified - would need to accumulate for streaming) - state->url = std::string_view(at, length); + // Accumulate URL data + state->url.append(at, length); return 0; } diff --git a/src/http_handler.hpp b/src/http_handler.hpp index 8fae3b7..18d1abc 100644 --- a/src/http_handler.hpp +++ b/src/http_handler.hpp @@ -46,7 +46,10 @@ struct HttpRequestState { // Current request data (arena-allocated) std::string_view method; - std::string_view url; + + using ArenaString = + std::basic_string, ArenaStlAllocator>; + ArenaString url; // Parse state bool headers_complete = false; @@ -59,8 +62,6 @@ struct HttpRequestState { status_request_id; // Request ID extracted from /v1/status/{id} URL // Header accumulation buffers (arena-allocated) - using ArenaString = - std::basic_string, ArenaStlAllocator>; ArenaString current_header_field_buf; ArenaString current_header_value_buf; bool header_field_complete = false;