changeset 8706:3057bae4dba7 quic

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.
author Roman Arutyunyan <arut@nginx.com>
date Wed, 17 Feb 2021 15:56:34 +0300
parents ae2e68f206f9
children ffcaf0aad9f2
files src/http/ngx_http.h src/http/ngx_http_request.h src/http/v3/ngx_http_v3.h src/http/v3/ngx_http_v3_request.c
diffstat 4 files changed, 16 insertions(+), 23 deletions(-) [+]
line wrap: on
line diff
--- a/src/http/ngx_http.h
+++ b/src/http/ngx_http.h
@@ -20,6 +20,7 @@ typedef struct ngx_http_file_cache_s  ng
 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);
--- 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;
 };
--- 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;
--- 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 
         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
     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;