Mercurial > hg > nginx
comparison src/http/ngx_http_core_module.c @ 8024:ef6a3a99a81a
Reworked multi headers to use linked lists.
Multi headers are now using linked lists instead of arrays. Notably,
the following fields were changed: r->headers_in.cookies (renamed
to r->headers_in.cookie), r->headers_in.x_forwarded_for,
r->headers_out.cache_control, r->headers_out.link, u->headers_in.cache_control
u->headers_in.cookies (renamed to u->headers_in.set_cookie).
The r->headers_in.cookies and u->headers_in.cookies fields were renamed
to r->headers_in.cookie and u->headers_in.set_cookie to match header names.
The ngx_http_parse_multi_header_lines() and ngx_http_parse_set_cookie_lines()
functions were changed accordingly.
With this change, multi headers are now essentially equivalent to normal
headers, and following changes will further make them equivalent.
author | Maxim Dounin <mdounin@mdounin.ru> |
---|---|
date | Mon, 30 May 2022 21:25:33 +0300 |
parents | f8f6b9fee66a |
children | d26db4f82d7d |
comparison
equal
deleted
inserted
replaced
8023:08b3ea81ff5f | 8024:ef6a3a99a81a |
---|---|
2022 ngx_int_t | 2022 ngx_int_t |
2023 ngx_http_gzip_ok(ngx_http_request_t *r) | 2023 ngx_http_gzip_ok(ngx_http_request_t *r) |
2024 { | 2024 { |
2025 time_t date, expires; | 2025 time_t date, expires; |
2026 ngx_uint_t p; | 2026 ngx_uint_t p; |
2027 ngx_array_t *cc; | 2027 ngx_table_elt_t *e, *d, *ae, *cc; |
2028 ngx_table_elt_t *e, *d, *ae; | |
2029 ngx_http_core_loc_conf_t *clcf; | 2028 ngx_http_core_loc_conf_t *clcf; |
2030 | 2029 |
2031 r->gzip_tested = 1; | 2030 r->gzip_tested = 1; |
2032 | 2031 |
2033 if (r != r->main) { | 2032 if (r != r->main) { |
2116 } | 2115 } |
2117 | 2116 |
2118 return NGX_DECLINED; | 2117 return NGX_DECLINED; |
2119 } | 2118 } |
2120 | 2119 |
2121 cc = &r->headers_out.cache_control; | 2120 cc = r->headers_out.cache_control; |
2122 | 2121 |
2123 if (cc->elts) { | 2122 if (cc) { |
2124 | 2123 |
2125 if ((p & NGX_HTTP_GZIP_PROXIED_NO_CACHE) | 2124 if ((p & NGX_HTTP_GZIP_PROXIED_NO_CACHE) |
2126 && ngx_http_parse_multi_header_lines(cc, &ngx_http_gzip_no_cache, | 2125 && ngx_http_parse_multi_header_lines(r, cc, &ngx_http_gzip_no_cache, |
2127 NULL) | 2126 NULL) |
2128 >= 0) | 2127 != NULL) |
2129 { | 2128 { |
2130 goto ok; | 2129 goto ok; |
2131 } | 2130 } |
2132 | 2131 |
2133 if ((p & NGX_HTTP_GZIP_PROXIED_NO_STORE) | 2132 if ((p & NGX_HTTP_GZIP_PROXIED_NO_STORE) |
2134 && ngx_http_parse_multi_header_lines(cc, &ngx_http_gzip_no_store, | 2133 && ngx_http_parse_multi_header_lines(r, cc, &ngx_http_gzip_no_store, |
2135 NULL) | 2134 NULL) |
2136 >= 0) | 2135 != NULL) |
2137 { | 2136 { |
2138 goto ok; | 2137 goto ok; |
2139 } | 2138 } |
2140 | 2139 |
2141 if ((p & NGX_HTTP_GZIP_PROXIED_PRIVATE) | 2140 if ((p & NGX_HTTP_GZIP_PROXIED_PRIVATE) |
2142 && ngx_http_parse_multi_header_lines(cc, &ngx_http_gzip_private, | 2141 && ngx_http_parse_multi_header_lines(r, cc, &ngx_http_gzip_private, |
2143 NULL) | 2142 NULL) |
2144 >= 0) | 2143 != NULL) |
2145 { | 2144 { |
2146 goto ok; | 2145 goto ok; |
2147 } | 2146 } |
2148 | 2147 |
2149 return NGX_DECLINED; | 2148 return NGX_DECLINED; |
2710 } | 2709 } |
2711 | 2710 |
2712 | 2711 |
2713 ngx_int_t | 2712 ngx_int_t |
2714 ngx_http_get_forwarded_addr(ngx_http_request_t *r, ngx_addr_t *addr, | 2713 ngx_http_get_forwarded_addr(ngx_http_request_t *r, ngx_addr_t *addr, |
2715 ngx_array_t *headers, ngx_str_t *value, ngx_array_t *proxies, | 2714 ngx_table_elt_t *headers, ngx_str_t *value, ngx_array_t *proxies, |
2716 int recursive) | 2715 int recursive) |
2717 { | 2716 { |
2718 ngx_int_t rc; | 2717 ngx_int_t rc; |
2719 ngx_uint_t i, found; | 2718 ngx_uint_t found; |
2720 ngx_table_elt_t **h; | 2719 ngx_table_elt_t *h, *next; |
2721 | 2720 |
2722 if (headers == NULL) { | 2721 if (headers == NULL) { |
2723 return ngx_http_get_forwarded_addr_internal(r, addr, value->data, | 2722 return ngx_http_get_forwarded_addr_internal(r, addr, value->data, |
2724 value->len, proxies, | 2723 value->len, proxies, |
2725 recursive); | 2724 recursive); |
2726 } | 2725 } |
2727 | 2726 |
2728 i = headers->nelts; | 2727 /* revert headers order */ |
2729 h = headers->elts; | 2728 |
2729 for (h = headers, headers = NULL; h; h = next) { | |
2730 next = h->next; | |
2731 h->next = headers; | |
2732 headers = h; | |
2733 } | |
2734 | |
2735 /* iterate over all headers in reverse order */ | |
2730 | 2736 |
2731 rc = NGX_DECLINED; | 2737 rc = NGX_DECLINED; |
2732 | 2738 |
2733 found = 0; | 2739 found = 0; |
2734 | 2740 |
2735 while (i-- > 0) { | 2741 for (h = headers; h; h = h->next) { |
2736 rc = ngx_http_get_forwarded_addr_internal(r, addr, h[i]->value.data, | 2742 rc = ngx_http_get_forwarded_addr_internal(r, addr, h->value.data, |
2737 h[i]->value.len, proxies, | 2743 h->value.len, proxies, |
2738 recursive); | 2744 recursive); |
2739 | 2745 |
2740 if (!recursive) { | 2746 if (!recursive) { |
2741 break; | 2747 break; |
2742 } | 2748 } |
2749 if (rc != NGX_OK) { | 2755 if (rc != NGX_OK) { |
2750 break; | 2756 break; |
2751 } | 2757 } |
2752 | 2758 |
2753 found = 1; | 2759 found = 1; |
2760 } | |
2761 | |
2762 /* restore headers order */ | |
2763 | |
2764 for (h = headers, headers = NULL; h; h = next) { | |
2765 next = h->next; | |
2766 h->next = headers; | |
2767 headers = h; | |
2754 } | 2768 } |
2755 | 2769 |
2756 return rc; | 2770 return rc; |
2757 } | 2771 } |
2758 | 2772 |