This commit is contained in:
Hiroaki Nakamura 2026-02-03 13:41:58 -08:00 committed by GitHub
commit bcf131a73a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 31 additions and 0 deletions

View file

@ -1541,6 +1541,7 @@ ngx_http_process_request_headers(ngx_event_t *rev)
"http header done");
r->request_length += r->header_in->pos - r->header_name_start;
r->request_header_length = r->request_length;
r->http_state = NGX_HTTP_PROCESS_REQUEST_STATE;

View file

@ -450,6 +450,7 @@ struct ngx_http_request_s {
size_t header_size;
off_t request_length;
off_t request_header_length;
ngx_uint_t err_status;

View file

@ -105,6 +105,8 @@ static ngx_int_t ngx_http_variable_request_body_file(ngx_http_request_t *r,
ngx_http_variable_value_t *v, uintptr_t data);
static ngx_int_t ngx_http_variable_request_length(ngx_http_request_t *r,
ngx_http_variable_value_t *v, uintptr_t data);
static ngx_int_t ngx_http_variable_request_body_length(ngx_http_request_t *r,
ngx_http_variable_value_t *v, uintptr_t data);
static ngx_int_t ngx_http_variable_request_time(ngx_http_request_t *r,
ngx_http_variable_value_t *v, uintptr_t data);
static ngx_int_t ngx_http_variable_request_id(ngx_http_request_t *r,
@ -309,6 +311,9 @@ static ngx_http_variable_t ngx_http_core_variables[] = {
{ ngx_string("request_length"), NULL, ngx_http_variable_request_length,
0, NGX_HTTP_VAR_NOCACHEABLE, 0 },
{ ngx_string("request_body_length"), NULL, ngx_http_variable_request_body_length,
0, NGX_HTTP_VAR_NOCACHEABLE, 0 },
{ ngx_string("request_time"), NULL, ngx_http_variable_request_time,
0, NGX_HTTP_VAR_NOCACHEABLE, 0 },
@ -2265,6 +2270,28 @@ ngx_http_variable_request_length(ngx_http_request_t *r,
}
static ngx_int_t
ngx_http_variable_request_body_length(ngx_http_request_t *r,
ngx_http_variable_value_t *v, uintptr_t data)
{
u_char *p;
p = ngx_pnalloc(r->pool, NGX_OFF_T_LEN);
if (p == NULL) {
return NGX_ERROR;
}
v->len = ngx_sprintf(p, "%O",
r->request_length - r->request_header_length) - p;
v->valid = 1;
v->no_cacheable = 0;
v->not_found = 0;
v->data = p;
return NGX_OK;
}
static ngx_int_t
ngx_http_variable_request_time(ngx_http_request_t *r,
ngx_http_variable_value_t *v, uintptr_t data)

View file

@ -3886,6 +3886,7 @@ ngx_http_v2_run_request(ngx_http_request_t *r)
h2c = r->stream->connection;
h2c->payload_bytes += r->request_length;
r->request_header_length = r->request_length;
ngx_http_process_request(r);

View file

@ -551,6 +551,7 @@ ngx_http_v3_process_request(ngx_event_t *rev)
r->request_length += b->pos - p;
h3c->total_bytes += b->pos - p;
r->request_header_length = r->request_length;
if (ngx_http_v3_check_flood(c) != NGX_OK) {
ngx_http_close_request(r, NGX_HTTP_CLOSE);