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