FEATURE: Add missing JSON fields and fix socket type per architecture.yml
- Add req_id, scheme, unparsed_uri, args, keepalives, content_length fields - Change socket type from SOCK_STREAM to SOCK_DGRAM - Update architecture.yml documentation with new fields - Bump version to 1.0.8 with changelog entry Co-authored-by: Qwen-Coder <qwen-coder@alibabacloud.com>
This commit is contained in:
@ -524,7 +524,7 @@ static int try_connect(reqin_log_config_t *cfg, reqin_log_child_state_t *state,
|
||||
state->last_connect_attempt = now;
|
||||
|
||||
if (state->socket_fd < 0) {
|
||||
state->socket_fd = socket(AF_UNIX, SOCK_STREAM, 0);
|
||||
state->socket_fd = socket(AF_UNIX, SOCK_DGRAM, 0);
|
||||
if (state->socket_fd < 0) {
|
||||
err = errno;
|
||||
state->connect_failed = 1;
|
||||
@ -668,6 +668,12 @@ static void log_request(request_rec *r, reqin_log_config_t *cfg, reqin_log_child
|
||||
const char *path;
|
||||
const char *host;
|
||||
const char *http_version;
|
||||
const char *scheme;
|
||||
const char *unparsed_uri;
|
||||
const char *args;
|
||||
const char *req_id;
|
||||
const char *content_length_str;
|
||||
apr_int64_t content_length;
|
||||
|
||||
if (!r || !r->server || !r->pool || !r->connection) {
|
||||
return;
|
||||
@ -707,6 +713,42 @@ static void log_request(request_rec *r, reqin_log_config_t *cfg, reqin_log_child
|
||||
http_version = apr_pstrmemdup(pool, http_version, 16);
|
||||
}
|
||||
|
||||
/* scheme (https or http) */
|
||||
scheme = ap_http_scheme(r);
|
||||
if (scheme == NULL) {
|
||||
scheme = "http";
|
||||
}
|
||||
|
||||
/* unparsed_uri (raw, unnormalized URI) */
|
||||
unparsed_uri = r->unparsed_uri ? r->unparsed_uri : "";
|
||||
/* Sanitize unparsed_uri to prevent oversized values */
|
||||
if (strlen(unparsed_uri) > 2048) {
|
||||
unparsed_uri = apr_pstrmemdup(pool, unparsed_uri, 2048);
|
||||
}
|
||||
|
||||
/* args (query string) */
|
||||
args = r->args ? r->args : "";
|
||||
/* Sanitize args to prevent oversized values */
|
||||
if (strlen(args) > 2048) {
|
||||
args = apr_pstrmemdup(pool, args, 2048);
|
||||
}
|
||||
|
||||
/* req_id (unique request identifier from Apache) */
|
||||
req_id = r->log_id ? r->log_id : "";
|
||||
|
||||
/* content_length (from Content-Length header) */
|
||||
content_length_str = apr_table_get(r->headers_in, "Content-Length");
|
||||
if (content_length_str != NULL) {
|
||||
char *endptr;
|
||||
errno = 0;
|
||||
content_length = strtoll(content_length_str, &endptr, 10);
|
||||
if (errno != 0 || endptr == content_length_str || *endptr != '\0' || content_length < 0) {
|
||||
content_length = 0;
|
||||
}
|
||||
} else {
|
||||
content_length = 0;
|
||||
}
|
||||
|
||||
dynbuf_init(&buf, pool, 4096);
|
||||
|
||||
dynbuf_append(&buf, "{", 1);
|
||||
@ -728,6 +770,16 @@ static void log_request(request_rec *r, reqin_log_config_t *cfg, reqin_log_child
|
||||
dynbuf_append(&buf, ",", 1);
|
||||
}
|
||||
|
||||
/* req_id (unique request identifier) */
|
||||
dynbuf_append(&buf, "\"req_id\":\"", 9);
|
||||
append_json_string(&buf, req_id);
|
||||
dynbuf_append(&buf, "\",", 2);
|
||||
|
||||
/* scheme (http or https) */
|
||||
dynbuf_append(&buf, "\"scheme\":\"", 10);
|
||||
append_json_string(&buf, scheme);
|
||||
dynbuf_append(&buf, "\",", 2);
|
||||
|
||||
/* src_ip */
|
||||
dynbuf_append(&buf, "\"src_ip\":\"", 10);
|
||||
append_json_string(&buf, src_ip);
|
||||
@ -768,6 +820,16 @@ static void log_request(request_rec *r, reqin_log_config_t *cfg, reqin_log_child
|
||||
append_json_string(&buf, path);
|
||||
dynbuf_append(&buf, "\",", 2);
|
||||
|
||||
/* unparsed_uri (raw, unnormalized URI) */
|
||||
dynbuf_append(&buf, "\"unparsed_uri\":\"", 16);
|
||||
append_json_string(&buf, unparsed_uri);
|
||||
dynbuf_append(&buf, "\",", 2);
|
||||
|
||||
/* args (query string) */
|
||||
dynbuf_append(&buf, "\"args\":\"", 8);
|
||||
append_json_string(&buf, args);
|
||||
dynbuf_append(&buf, "\",", 2);
|
||||
|
||||
/* host */
|
||||
dynbuf_append(&buf, "\"host\":\"", 8);
|
||||
append_json_string(&buf, host);
|
||||
@ -778,6 +840,22 @@ static void log_request(request_rec *r, reqin_log_config_t *cfg, reqin_log_child
|
||||
append_json_string(&buf, http_version);
|
||||
dynbuf_append(&buf, "\"", 1);
|
||||
|
||||
/* keepalives (number of requests on this connection) */
|
||||
dynbuf_append(&buf, ",\"keepalives\":", 15);
|
||||
{
|
||||
char ka_buf[16];
|
||||
snprintf(ka_buf, sizeof(ka_buf), "%d", r->connection->keepalives);
|
||||
dynbuf_append(&buf, ka_buf, -1);
|
||||
}
|
||||
|
||||
/* content_length (from Content-Length header) */
|
||||
dynbuf_append(&buf, ",\"content_length\":", 18);
|
||||
{
|
||||
char cl_buf[32];
|
||||
snprintf(cl_buf, sizeof(cl_buf), "%" APR_INT64_T_FMT, content_length);
|
||||
dynbuf_append(&buf, cl_buf, -1);
|
||||
}
|
||||
|
||||
/* Check buffer size before adding headers to prevent memory exhaustion */
|
||||
if (buf.len >= MAX_JSON_SIZE) {
|
||||
if (SHOULD_LOG(srv_conf, REQIN_LOG_LEVEL_DEBUG)) {
|
||||
|
||||
Reference in New Issue
Block a user