]> git.kaiwu.me - nginx.git/commitdiff
All known output headers can be linked lists now.
authorMaxim Dounin <mdounin@mdounin.ru>
Mon, 30 May 2022 18:25:45 +0000 (21:25 +0300)
committerMaxim Dounin <mdounin@mdounin.ru>
Mon, 30 May 2022 18:25:45 +0000 (21:25 +0300)
The h->next pointer properly provided as NULL in all cases where known
output headers are added.

Note that there are 3rd party modules which might not do this, and it
might be risky to rely on this for arbitrary headers.

14 files changed:
src/http/modules/ngx_http_auth_basic_module.c
src/http/modules/ngx_http_auth_request_module.c
src/http/modules/ngx_http_dav_module.c
src/http/modules/ngx_http_gzip_filter_module.c
src/http/modules/ngx_http_gzip_static_module.c
src/http/modules/ngx_http_headers_filter_module.c
src/http/modules/ngx_http_memcached_module.c
src/http/modules/ngx_http_range_filter_module.c
src/http/modules/ngx_http_static_module.c
src/http/modules/perl/nginx.xs
src/http/ngx_http_core_module.c
src/http/ngx_http_script.c
src/http/ngx_http_special_response.c
src/http/ngx_http_upstream.c

index 069331982c327ee7e14bc99d10ccce9859792988..02d41e88a95e0db3d6bf5b8e7af331de2db8887e 100644 (file)
@@ -339,6 +339,7 @@ ngx_http_auth_basic_set_realm(ngx_http_request_t *r, ngx_str_t *realm)
     *p = '"';
 
     r->headers_out.www_authenticate->hash = 1;
+    r->headers_out.www_authenticate->next = NULL;
     ngx_str_set(&r->headers_out.www_authenticate->key, "WWW-Authenticate");
     r->headers_out.www_authenticate->value.data = basic;
     r->headers_out.www_authenticate->value.len = len;
index bab79e4961a755f2c61079ea4a18a1155a393e12..f64ab09aa59a03fb6fb43ff1c3052207d905f8c5 100644 (file)
@@ -154,6 +154,7 @@ ngx_http_auth_request_handler(ngx_http_request_t *r)
                 }
 
                 *ho = *h;
+                ho->next = NULL;
 
                 r->headers_out.www_authenticate = ho;
             }
index 0cc9ae18bf00af5310ae38372cbca2d5d61e5729..cfb98929e97ead0f00edc684827d1defede8b3a5 100644 (file)
@@ -1082,6 +1082,7 @@ ngx_http_dav_location(ngx_http_request_t *r)
     }
 
     r->headers_out.location->hash = 1;
+    r->headers_out.location->next = NULL;
     ngx_str_set(&r->headers_out.location->key, "Location");
 
     escape = 2 * ngx_escape_uri(NULL, r->uri.data, r->uri.len, NGX_ESCAPE_URI);
index b8c5ccc5c510d5897d4695ebe0c62268124553bd..b7758690fe2754f34d43024c4467075c5e4edf2a 100644 (file)
@@ -280,6 +280,7 @@ ngx_http_gzip_header_filter(ngx_http_request_t *r)
     }
 
     h->hash = 1;
+    h->next = NULL;
     ngx_str_set(&h->key, "Content-Encoding");
     ngx_str_set(&h->value, "gzip");
     r->headers_out.content_encoding = h;
index 7652a9af3effbadb1e18892c28bc1e0d7dac3b82..66fcc5d1bf57a79595a95b1d4526578676315838 100644 (file)
@@ -242,6 +242,7 @@ ngx_http_gzip_static_handler(ngx_http_request_t *r)
     }
 
     h->hash = 1;
+    h->next = NULL;
     ngx_str_set(&h->key, "Content-Encoding");
     ngx_str_set(&h->value, "gzip");
     r->headers_out.content_encoding = h;
index 995beb41bf59faff899287846f8f8978b0288988..50295f452d1bab1c89ae6d751cec4dd1a92026dd 100644 (file)
@@ -362,6 +362,7 @@ ngx_http_set_expires(ngx_http_request_t *r, ngx_http_headers_conf_t *conf)
         }
 
         r->headers_out.expires = e;
+        e->next = NULL;
 
         e->hash = 1;
         ngx_str_set(&e->key, "Expires");
@@ -621,6 +622,7 @@ ngx_http_set_response_header(ngx_http_request_t *r, ngx_http_header_val_t *hv,
         }
 
         *old = h;
+        h->next = NULL;
     }
 
     h->hash = 1;
index c82df6e33738bbd6ac1dd97a8012d195fea7fa30..11bbd91659c76fe34592315e895a482d8f04b3d4 100644 (file)
@@ -401,6 +401,7 @@ found:
             }
 
             h->hash = 1;
+            h->next = NULL;
             ngx_str_set(&h->key, "Content-Encoding");
             ngx_str_set(&h->value, "gzip");
             r->headers_out.content_encoding = h;
index ae08ebbc50c61272f29058eaf7ffb51074a8f0a4..fa408b792aec860c0c0af3e239cd97ded89d693b 100644 (file)
@@ -258,6 +258,7 @@ next_filter:
     }
 
     r->headers_out.accept_ranges->hash = 1;
+    r->headers_out.accept_ranges->next = NULL;
     ngx_str_set(&r->headers_out.accept_ranges->key, "Accept-Ranges");
     ngx_str_set(&r->headers_out.accept_ranges->value, "bytes");
 
@@ -427,6 +428,7 @@ ngx_http_range_singlepart_header(ngx_http_request_t *r,
     r->headers_out.content_range = content_range;
 
     content_range->hash = 1;
+    content_range->next = NULL;
     ngx_str_set(&content_range->key, "Content-Range");
 
     content_range->value.data = ngx_pnalloc(r->pool,
@@ -599,6 +601,7 @@ ngx_http_range_not_satisfiable(ngx_http_request_t *r)
     r->headers_out.content_range = content_range;
 
     content_range->hash = 1;
+    content_range->next = NULL;
     ngx_str_set(&content_range->key, "Content-Range");
 
     content_range->value.data = ngx_pnalloc(r->pool,
index cf29d5a6da17c574c775df9cb899b222a42c0cbf..e30565d4ee5c13f230567faedfc91823b3ded3f9 100644 (file)
@@ -195,6 +195,7 @@ ngx_http_static_handler(ngx_http_request_t *r)
         }
 
         r->headers_out.location->hash = 1;
+        r->headers_out.location->next = NULL;
         ngx_str_set(&r->headers_out.location->key, "Location");
         r->headers_out.location->value.len = len;
         r->headers_out.location->value.data = location;
index c398e77d745ea9da043d407dde6b2a9916fb5fda..da12279528ef3a9e7919a1e65df212366590d987 100644 (file)
@@ -573,6 +573,7 @@ header_out(r, key, value)
     }
 
     header->hash = 1;
+    header->next = NULL;
 
     if (ngx_http_perl_sv2str(aTHX_ r, &header->key, key) != NGX_OK) {
         header->hash = 0;
index afb0862844e96373b0efb4d5261e61718a69d47e..0c7dd3f99349eb37ab755f95d6f2a7e6e2938eb9 100644 (file)
@@ -1007,6 +1007,7 @@ ngx_http_core_find_config_phase(ngx_http_request_t *r,
         }
 
         r->headers_out.location->hash = 1;
+        r->headers_out.location->next = NULL;
         ngx_str_set(&r->headers_out.location->key, "Location");
 
         if (r->args.len == 0) {
@@ -1687,6 +1688,7 @@ ngx_http_set_etag(ngx_http_request_t *r)
     }
 
     etag->hash = 1;
+    etag->next = NULL;
     ngx_str_set(&etag->key, "ETag");
 
     etag->value.data = ngx_pnalloc(r->pool, NGX_OFF_T_LEN + NGX_TIME_T_LEN + 3);
@@ -1781,6 +1783,7 @@ ngx_http_send_response(ngx_http_request_t *r, ngx_uint_t status,
         }
 
         r->headers_out.location->hash = 1;
+        r->headers_out.location->next = NULL;
         ngx_str_set(&r->headers_out.location->key, "Location");
         r->headers_out.location->value = val;
 
index bebdbd92b88e2f23927727eb90ec35a0d1a12fd7..a2b9f1b7bf5e63151a945a110cfad900b2f1d2f2 100644 (file)
@@ -1243,6 +1243,7 @@ ngx_http_script_regex_end_code(ngx_http_script_engine_t *e)
         }
 
         r->headers_out.location->hash = 1;
+        r->headers_out.location->next = NULL;
         ngx_str_set(&r->headers_out.location->key, "Location");
         r->headers_out.location->value = e->buf;
 
index 72f56fd9adc5b86006fc450c0961630a6f9ee5cd..eaf42e39911787d99400622c8617bdd2c7be69c1 100644 (file)
@@ -649,6 +649,7 @@ ngx_http_send_error_page(ngx_http_request_t *r, ngx_http_err_page_t *err_page)
     }
 
     location->hash = 1;
+    location->next = NULL;
     ngx_str_set(&location->key, "Location");
     location->value = uri;
 
index b480f555944cee9a59082830b3938d09acb34185..73936f714ad80f567b97e0d497831747ccfd985b 100644 (file)
@@ -2681,6 +2681,7 @@ ngx_http_upstream_intercept_errors(ngx_http_request_t *r,
                 }
 
                 *h = *u->headers_in.www_authenticate;
+                h->next = NULL;
 
                 r->headers_out.www_authenticate = h;
             }
@@ -5075,6 +5076,7 @@ ngx_http_upstream_copy_header_line(ngx_http_request_t *r, ngx_table_elt_t *h,
     if (offset) {
         ph = (ngx_table_elt_t **) ((char *) &r->headers_out + offset);
         *ph = ho;
+        ho->next = NULL;
     }
 
     return NGX_OK;
@@ -5169,6 +5171,7 @@ ngx_http_upstream_copy_last_modified(ngx_http_request_t *r, ngx_table_elt_t *h,
     }
 
     *ho = *h;
+    ho->next = NULL;
 
     r->headers_out.last_modified = ho;
     r->headers_out.last_modified_time =
@@ -5191,6 +5194,7 @@ ngx_http_upstream_rewrite_location(ngx_http_request_t *r, ngx_table_elt_t *h,
     }
 
     *ho = *h;
+    ho->next = NULL;
 
     if (r->upstream->rewrite_redirect) {
         rc = r->upstream->rewrite_redirect(r, ho, 0);
@@ -5236,6 +5240,7 @@ ngx_http_upstream_rewrite_refresh(ngx_http_request_t *r, ngx_table_elt_t *h,
     }
 
     *ho = *h;
+    ho->next = NULL;
 
     if (r->upstream->rewrite_redirect) {
 
@@ -5281,6 +5286,7 @@ ngx_http_upstream_rewrite_set_cookie(ngx_http_request_t *r, ngx_table_elt_t *h,
     }
 
     *ho = *h;
+    ho->next = NULL;
 
     if (r->upstream->rewrite_cookie) {
         rc = r->upstream->rewrite_cookie(r, ho);
@@ -5334,6 +5340,7 @@ ngx_http_upstream_copy_allow_ranges(ngx_http_request_t *r,
     }
 
     *ho = *h;
+    ho->next = NULL;
 
     r->headers_out.accept_ranges = ho;