From ffb099bf52e70c0cbdb1ed5555645f12ec6b2322 Mon Sep 17 00:00:00 2001 From: Roman Arutyunyan Date: Wed, 17 Feb 2021 15:56:34 +0300 Subject: [PATCH] HTTP/3: introduced ngx_http_v3_parse_t structure. The structure is used to parse an HTTP/3 request. An object of this type is added to ngx_http_request_t instead of h3_parse generic pointer. Also, the new field is located outside of the request ephemeral zone to keep it safe after request headers are parsed. --- src/http/ngx_http.h | 1 + src/http/ngx_http_request.h | 5 +---- src/http/v3/ngx_http_v3.h | 6 ++++++ src/http/v3/ngx_http_v3_request.c | 27 ++++++++------------------- 4 files changed, 16 insertions(+), 23 deletions(-) diff --git a/src/http/ngx_http.h b/src/http/ngx_http.h index a7cd51d53..f5d772e65 100644 --- a/src/http/ngx_http.h +++ b/src/http/ngx_http.h @@ -20,6 +20,7 @@ typedef struct ngx_http_file_cache_s ngx_http_file_cache_t; typedef struct ngx_http_log_ctx_s ngx_http_log_ctx_t; typedef struct ngx_http_chunked_s ngx_http_chunked_t; typedef struct ngx_http_v2_stream_s ngx_http_v2_stream_t; +typedef struct ngx_http_v3_parse_s ngx_http_v3_parse_t; typedef ngx_int_t (*ngx_http_header_handler_pt)(ngx_http_request_t *r, ngx_table_elt_t *h, ngx_uint_t offset); diff --git a/src/http/ngx_http_request.h b/src/http/ngx_http_request.h index 4121e3c3b..5231ad6f2 100644 --- a/src/http/ngx_http_request.h +++ b/src/http/ngx_http_request.h @@ -447,6 +447,7 @@ struct ngx_http_request_s { ngx_http_connection_t *http_connection; ngx_http_v2_stream_t *stream; + ngx_http_v3_parse_t *v3_parse; ngx_http_log_handler_pt log_handler; @@ -596,10 +597,6 @@ struct ngx_http_request_s { u_char *port_start; u_char *port_end; -#if (NGX_HTTP_V3) - void *h3_parse; -#endif - unsigned http_minor:16; unsigned http_major:16; }; diff --git a/src/http/v3/ngx_http_v3.h b/src/http/v3/ngx_http_v3.h index 5223d8f75..2b0693975 100644 --- a/src/http/v3/ngx_http_v3.h +++ b/src/http/v3/ngx_http_v3.h @@ -98,6 +98,12 @@ typedef struct { } ngx_http_v3_loc_conf_t; +struct ngx_http_v3_parse_s { + ngx_http_v3_parse_headers_t headers; + ngx_http_v3_parse_data_t body; +}; + + typedef struct { ngx_str_t name; ngx_str_t value; diff --git a/src/http/v3/ngx_http_v3_request.c b/src/http/v3/ngx_http_v3_request.c index df58f383a..ef3053689 100644 --- a/src/http/v3/ngx_http_v3_request.c +++ b/src/http/v3/ngx_http_v3_request.c @@ -112,6 +112,12 @@ ngx_http_v3_init(ngx_connection_t *c) r->http_version = NGX_HTTP_VERSION_30; + r->v3_parse = ngx_pcalloc(r->pool, sizeof(ngx_http_v3_parse_t)); + if (r->v3_parse == NULL) { + ngx_http_close_connection(c); + return; + } + c->data = r; rev = c->read; @@ -144,17 +150,7 @@ ngx_http_v3_process_request(ngx_event_t *rev) return; } - st = r->h3_parse; - - if (st == NULL) { - st = ngx_pcalloc(c->pool, sizeof(ngx_http_v3_parse_headers_t)); - if (st == NULL) { - ngx_http_finalize_request(r, NGX_HTTP_BAD_REQUEST); - return; - } - - r->h3_parse = st; - } + st = &r->v3_parse->headers; b = r->header_in; @@ -949,20 +945,13 @@ ngx_http_v3_request_body_filter(ngx_http_request_t *r, ngx_chain_t *in) ngx_http_v3_parse_data_t *st; rb = r->request_body; - st = r->h3_parse; + st = &r->v3_parse->body; if (rb->rest == -1) { ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, "http3 request body filter"); - st = ngx_pcalloc(r->pool, sizeof(ngx_http_v3_parse_data_t)); - if (st == NULL) { - return NGX_HTTP_INTERNAL_SERVER_ERROR; - } - - r->h3_parse = st; - cscf = ngx_http_get_module_srv_conf(r, ngx_http_core_module); rb->rest = cscf->large_client_header_buffers.size;