]> git.feebdaed.xyz Git - 0xmirror/nginx.git/commitdiff
HTTP/2: factored out constructing the Host header.
authorSergey Kandaurov <pluknet@nginx.com>
Wed, 23 Jul 2025 10:32:34 +0000 (14:32 +0400)
committerpluknet <pluknet@nginx.com>
Sun, 3 Aug 2025 06:07:07 +0000 (10:07 +0400)
No functional changes.

src/http/v2/ngx_http_v2.c

index 91a28b2281b8252f08aac633aa973e2a039a3e05..c9ef6d7ee5d4de2e8b5ec542de161b94d66da9a9 100644 (file)
@@ -158,6 +158,8 @@ static ngx_int_t ngx_http_v2_construct_request_line(ngx_http_request_t *r);
 static ngx_int_t ngx_http_v2_cookie(ngx_http_request_t *r,
     ngx_http_v2_header_t *header);
 static ngx_int_t ngx_http_v2_construct_cookie_header(ngx_http_request_t *r);
+static ngx_int_t ngx_http_v2_construct_host_header(ngx_http_request_t *r,
+    ngx_str_t *value);
 static void ngx_http_v2_run_request(ngx_http_request_t *r);
 static ngx_int_t ngx_http_v2_process_request_body(ngx_http_request_t *r,
     u_char *pos, size_t size, ngx_uint_t last, ngx_uint_t flush);
@@ -3517,45 +3519,7 @@ ngx_http_v2_parse_scheme(ngx_http_request_t *r, ngx_str_t *value)
 static ngx_int_t
 ngx_http_v2_parse_authority(ngx_http_request_t *r, ngx_str_t *value)
 {
-    ngx_table_elt_t            *h;
-    ngx_http_header_t          *hh;
-    ngx_http_core_main_conf_t  *cmcf;
-
-    static ngx_str_t host = ngx_string("host");
-
-    h = ngx_list_push(&r->headers_in.headers);
-    if (h == NULL) {
-        return NGX_ERROR;
-    }
-
-    h->hash = ngx_hash(ngx_hash(ngx_hash('h', 'o'), 's'), 't');
-
-    h->key.len = host.len;
-    h->key.data = host.data;
-
-    h->value.len = value->len;
-    h->value.data = value->data;
-
-    h->lowcase_key = host.data;
-
-    cmcf = ngx_http_get_module_main_conf(r, ngx_http_core_module);
-
-    hh = ngx_hash_find(&cmcf->headers_in_hash, h->hash,
-                       h->lowcase_key, h->key.len);
-
-    if (hh == NULL) {
-        return NGX_ERROR;
-    }
-
-    if (hh->handler(r, h, hh->offset) != NGX_OK) {
-        /*
-         * request has been finalized already
-         * in ngx_http_process_host()
-         */
-        return NGX_ABORT;
-    }
-
-    return NGX_OK;
+    return ngx_http_v2_construct_host_header(r, value);
 }
 
 
@@ -3734,6 +3698,51 @@ ngx_http_v2_construct_cookie_header(ngx_http_request_t *r)
 }
 
 
+static ngx_int_t
+ngx_http_v2_construct_host_header(ngx_http_request_t *r, ngx_str_t *value)
+{
+    ngx_table_elt_t            *h;
+    ngx_http_header_t          *hh;
+    ngx_http_core_main_conf_t  *cmcf;
+
+    static ngx_str_t host = ngx_string("host");
+
+    h = ngx_list_push(&r->headers_in.headers);
+    if (h == NULL) {
+        return NGX_ERROR;
+    }
+
+    h->hash = ngx_hash(ngx_hash(ngx_hash('h', 'o'), 's'), 't');
+
+    h->key.len = host.len;
+    h->key.data = host.data;
+
+    h->value.len = value->len;
+    h->value.data = value->data;
+
+    h->lowcase_key = host.data;
+
+    cmcf = ngx_http_get_module_main_conf(r, ngx_http_core_module);
+
+    hh = ngx_hash_find(&cmcf->headers_in_hash, h->hash,
+                       h->lowcase_key, h->key.len);
+
+    if (hh == NULL) {
+        return NGX_ERROR;
+    }
+
+    if (hh->handler(r, h, hh->offset) != NGX_OK) {
+        /*
+         * request has been finalized already
+         * in ngx_http_process_host()
+         */
+        return NGX_ABORT;
+    }
+
+    return NGX_OK;
+}
+
+
 static void
 ngx_http_v2_run_request(ngx_http_request_t *r)
 {