Perfetto tracing for /ok. Header parsing not complete
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
#include "http_handler.hpp"
|
||||
#include "arena_allocator.hpp"
|
||||
#include "perfetto_categories.hpp"
|
||||
#include <cstring>
|
||||
#include <string>
|
||||
#include <strings.h>
|
||||
@@ -213,6 +214,8 @@ void HttpHandler::handleGetMetrics(Connection &conn,
|
||||
|
||||
void HttpHandler::handleGetOk(Connection &conn,
|
||||
const HttpConnectionState &state) {
|
||||
TRACE_EVENT("http", "GET /ok", perfetto::Flow::Global(state.request_id));
|
||||
|
||||
sendResponse(conn, 200, "text/plain", "OK", state.connection_close);
|
||||
}
|
||||
|
||||
@@ -254,6 +257,8 @@ void HttpHandler::sendResponse(Connection &conn, int status_code,
|
||||
break;
|
||||
}
|
||||
|
||||
auto *state = static_cast<HttpConnectionState *>(conn.user_data);
|
||||
|
||||
response += "\r\n";
|
||||
response += "Content-Type: ";
|
||||
response += content_type;
|
||||
@@ -261,6 +266,9 @@ void HttpHandler::sendResponse(Connection &conn, int status_code,
|
||||
response += "Content-Length: ";
|
||||
response += std::to_string(body.size());
|
||||
response += "\r\n";
|
||||
response += "X-Response-ID: ";
|
||||
response += std::to_string(state->request_id);
|
||||
response += "\r\n";
|
||||
|
||||
if (close_connection) {
|
||||
response += "Connection: close\r\n";
|
||||
@@ -322,6 +330,20 @@ int HttpHandler::onHeaderValue(llhttp_t *parser, const char *at,
|
||||
}
|
||||
}
|
||||
|
||||
// Check for X-Request-Id header
|
||||
if (state->current_header_field.size() == 12 &&
|
||||
strncasecmp(state->current_header_field.data(), "x-request-id", 12) ==
|
||||
0) {
|
||||
uint64_t id = 0;
|
||||
for (int i = 0; i < int(length); ++i) {
|
||||
auto c = at[i];
|
||||
if (c >= '0' && c <= '9') {
|
||||
id = id * 10 + (c - '0');
|
||||
}
|
||||
}
|
||||
state->request_id = id;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -348,4 +370,4 @@ int HttpHandler::onMessageComplete(llhttp_t *parser) {
|
||||
auto *state = static_cast<HttpConnectionState *>(parser->data);
|
||||
state->message_complete = true;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user