Mercurial > hg > nginx
comparison src/http/ngx_http_upstream.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 | 08b3ea81ff5f |
children | 27d12017f300 |
comparison
equal
deleted
inserted
replaced
8023:08b3ea81ff5f | 8024:ef6a3a99a81a |
---|---|
244 ngx_http_upstream_ignore_header_line, 0, | 244 ngx_http_upstream_ignore_header_line, 0, |
245 ngx_http_upstream_rewrite_refresh, 0, 0 }, | 245 ngx_http_upstream_rewrite_refresh, 0, 0 }, |
246 | 246 |
247 { ngx_string("Set-Cookie"), | 247 { ngx_string("Set-Cookie"), |
248 ngx_http_upstream_process_set_cookie, | 248 ngx_http_upstream_process_set_cookie, |
249 offsetof(ngx_http_upstream_headers_in_t, cookies), | 249 offsetof(ngx_http_upstream_headers_in_t, set_cookie), |
250 ngx_http_upstream_rewrite_set_cookie, 0, 1 }, | 250 ngx_http_upstream_rewrite_set_cookie, 0, 1 }, |
251 | 251 |
252 { ngx_string("Content-Disposition"), | 252 { ngx_string("Content-Disposition"), |
253 ngx_http_upstream_ignore_header_line, 0, | 253 ngx_http_upstream_ignore_header_line, 0, |
254 ngx_http_upstream_copy_header_line, 0, 1 }, | 254 ngx_http_upstream_copy_header_line, 0, 1 }, |
4664 | 4664 |
4665 static ngx_int_t | 4665 static ngx_int_t |
4666 ngx_http_upstream_process_set_cookie(ngx_http_request_t *r, ngx_table_elt_t *h, | 4666 ngx_http_upstream_process_set_cookie(ngx_http_request_t *r, ngx_table_elt_t *h, |
4667 ngx_uint_t offset) | 4667 ngx_uint_t offset) |
4668 { | 4668 { |
4669 ngx_array_t *pa; | |
4670 ngx_table_elt_t **ph; | 4669 ngx_table_elt_t **ph; |
4671 ngx_http_upstream_t *u; | 4670 ngx_http_upstream_t *u; |
4672 | 4671 |
4673 u = r->upstream; | 4672 u = r->upstream; |
4674 pa = &u->headers_in.cookies; | 4673 ph = &u->headers_in.set_cookie; |
4675 | 4674 |
4676 if (pa->elts == NULL) { | 4675 while (*ph) { ph = &(*ph)->next; } |
4677 if (ngx_array_init(pa, r->pool, 1, sizeof(ngx_table_elt_t *)) != NGX_OK) | |
4678 { | |
4679 return NGX_ERROR; | |
4680 } | |
4681 } | |
4682 | |
4683 ph = ngx_array_push(pa); | |
4684 if (ph == NULL) { | |
4685 return NGX_ERROR; | |
4686 } | |
4687 | 4676 |
4688 *ph = h; | 4677 *ph = h; |
4678 h->next = NULL; | |
4689 | 4679 |
4690 #if (NGX_HTTP_CACHE) | 4680 #if (NGX_HTTP_CACHE) |
4691 if (!(u->conf->ignore_headers & NGX_HTTP_UPSTREAM_IGN_SET_COOKIE)) { | 4681 if (!(u->conf->ignore_headers & NGX_HTTP_UPSTREAM_IGN_SET_COOKIE)) { |
4692 u->cacheable = 0; | 4682 u->cacheable = 0; |
4693 } | 4683 } |
4699 | 4689 |
4700 static ngx_int_t | 4690 static ngx_int_t |
4701 ngx_http_upstream_process_cache_control(ngx_http_request_t *r, | 4691 ngx_http_upstream_process_cache_control(ngx_http_request_t *r, |
4702 ngx_table_elt_t *h, ngx_uint_t offset) | 4692 ngx_table_elt_t *h, ngx_uint_t offset) |
4703 { | 4693 { |
4704 ngx_array_t *pa; | |
4705 ngx_table_elt_t **ph; | 4694 ngx_table_elt_t **ph; |
4706 ngx_http_upstream_t *u; | 4695 ngx_http_upstream_t *u; |
4707 | 4696 |
4708 u = r->upstream; | 4697 u = r->upstream; |
4709 pa = &u->headers_in.cache_control; | 4698 ph = &u->headers_in.cache_control; |
4710 | 4699 |
4711 if (pa->elts == NULL) { | 4700 while (*ph) { ph = &(*ph)->next; } |
4712 if (ngx_array_init(pa, r->pool, 2, sizeof(ngx_table_elt_t *)) != NGX_OK) | |
4713 { | |
4714 return NGX_ERROR; | |
4715 } | |
4716 } | |
4717 | |
4718 ph = ngx_array_push(pa); | |
4719 if (ph == NULL) { | |
4720 return NGX_ERROR; | |
4721 } | |
4722 | 4701 |
4723 *ph = h; | 4702 *ph = h; |
4703 h->next = NULL; | |
4724 | 4704 |
4725 #if (NGX_HTTP_CACHE) | 4705 #if (NGX_HTTP_CACHE) |
4726 { | 4706 { |
4727 u_char *p, *start, *last; | 4707 u_char *p, *start, *last; |
4728 ngx_int_t n; | 4708 ngx_int_t n; |
5101 | 5081 |
5102 static ngx_int_t | 5082 static ngx_int_t |
5103 ngx_http_upstream_copy_multi_header_lines(ngx_http_request_t *r, | 5083 ngx_http_upstream_copy_multi_header_lines(ngx_http_request_t *r, |
5104 ngx_table_elt_t *h, ngx_uint_t offset) | 5084 ngx_table_elt_t *h, ngx_uint_t offset) |
5105 { | 5085 { |
5106 ngx_array_t *pa; | |
5107 ngx_table_elt_t *ho, **ph; | 5086 ngx_table_elt_t *ho, **ph; |
5108 | |
5109 pa = (ngx_array_t *) ((char *) &r->headers_out + offset); | |
5110 | |
5111 if (pa->elts == NULL) { | |
5112 if (ngx_array_init(pa, r->pool, 2, sizeof(ngx_table_elt_t *)) != NGX_OK) | |
5113 { | |
5114 return NGX_ERROR; | |
5115 } | |
5116 } | |
5117 | 5087 |
5118 ho = ngx_list_push(&r->headers_out.headers); | 5088 ho = ngx_list_push(&r->headers_out.headers); |
5119 if (ho == NULL) { | 5089 if (ho == NULL) { |
5120 return NGX_ERROR; | 5090 return NGX_ERROR; |
5121 } | 5091 } |
5122 | 5092 |
5123 *ho = *h; | 5093 *ho = *h; |
5124 | 5094 |
5125 ph = ngx_array_push(pa); | 5095 ph = (ngx_table_elt_t **) ((char *) &r->headers_out + offset); |
5126 if (ph == NULL) { | 5096 |
5127 return NGX_ERROR; | 5097 while (*ph) { ph = &(*ph)->next; } |
5128 } | |
5129 | 5098 |
5130 *ph = ho; | 5099 *ph = ho; |
5100 ho->next = NULL; | |
5131 | 5101 |
5132 return NGX_OK; | 5102 return NGX_OK; |
5133 } | 5103 } |
5134 | 5104 |
5135 | 5105 |
5738 } | 5708 } |
5739 | 5709 |
5740 s.len = name->len - (sizeof("upstream_cookie_") - 1); | 5710 s.len = name->len - (sizeof("upstream_cookie_") - 1); |
5741 s.data = name->data + sizeof("upstream_cookie_") - 1; | 5711 s.data = name->data + sizeof("upstream_cookie_") - 1; |
5742 | 5712 |
5743 if (ngx_http_parse_set_cookie_lines(&r->upstream->headers_in.cookies, | 5713 if (ngx_http_parse_set_cookie_lines(r, r->upstream->headers_in.set_cookie, |
5744 &s, &cookie) | 5714 &s, &cookie) |
5745 == NGX_DECLINED) | 5715 == NULL) |
5746 { | 5716 { |
5747 v->not_found = 1; | 5717 v->not_found = 1; |
5748 return NGX_OK; | 5718 return NGX_OK; |
5749 } | 5719 } |
5750 | 5720 |