aboutsummaryrefslogtreecommitdiff
path: root/src/http/ngx_http_variables.c
diff options
context:
space:
mode:
authorMaxim Dounin <mdounin@mdounin.ru>2022-05-30 21:25:33 +0300
committerMaxim Dounin <mdounin@mdounin.ru>2022-05-30 21:25:33 +0300
commit3aef1d693f3cc431563a7e6a6aba6a34e5290f03 (patch)
treef926dcda083c18517266b4fd1fabbbe51fbf6f5f /src/http/ngx_http_variables.c
parent7dc6f4e25d21588249691aab8c6013c126eae258 (diff)
downloadnginx-3aef1d693f3cc431563a7e6a6aba6a34e5290f03.tar.gz
nginx-3aef1d693f3cc431563a7e6a6aba6a34e5290f03.zip
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.
Diffstat (limited to 'src/http/ngx_http_variables.c')
-rw-r--r--src/http/ngx_http_variables.c41
1 files changed, 17 insertions, 24 deletions
diff --git a/src/http/ngx_http_variables.c b/src/http/ngx_http_variables.c
index b0f06ac7c..69462f10c 100644
--- a/src/http/ngx_http_variables.c
+++ b/src/http/ngx_http_variables.c
@@ -183,7 +183,7 @@ static ngx_http_variable_t ngx_http_core_variables[] = {
#endif
{ ngx_string("http_cookie"), NULL, ngx_http_variable_cookies,
- offsetof(ngx_http_request_t, headers_in.cookies), 0, 0 },
+ offsetof(ngx_http_request_t, headers_in.cookie), 0, 0 },
{ ngx_string("content_length"), NULL, ngx_http_variable_content_length,
0, 0, 0 },
@@ -846,26 +846,21 @@ static ngx_int_t
ngx_http_variable_headers_internal(ngx_http_request_t *r,
ngx_http_variable_value_t *v, uintptr_t data, u_char sep)
{
- size_t len;
- u_char *p, *end;
- ngx_uint_t i, n;
- ngx_array_t *a;
- ngx_table_elt_t **h;
-
- a = (ngx_array_t *) ((char *) r + data);
+ size_t len;
+ u_char *p;
+ ngx_table_elt_t *h, *th;
- n = a->nelts;
- h = a->elts;
+ h = *(ngx_table_elt_t **) ((char *) r + data);
len = 0;
- for (i = 0; i < n; i++) {
+ for (th = h; th; th = th->next) {
- if (h[i]->hash == 0) {
+ if (th->hash == 0) {
continue;
}
- len += h[i]->value.len + 2;
+ len += th->value.len + 2;
}
if (len == 0) {
@@ -879,9 +874,9 @@ ngx_http_variable_headers_internal(ngx_http_request_t *r,
v->no_cacheable = 0;
v->not_found = 0;
- if (n == 1) {
- v->len = (*h)->value.len;
- v->data = (*h)->value.data;
+ if (h->next == NULL) {
+ v->len = h->value.len;
+ v->data = h->value.data;
return NGX_OK;
}
@@ -894,17 +889,15 @@ ngx_http_variable_headers_internal(ngx_http_request_t *r,
v->len = len;
v->data = p;
- end = p + len;
-
- for (i = 0; /* void */ ; i++) {
+ for (th = h; th; th = th->next) {
- if (h[i]->hash == 0) {
+ if (th->hash == 0) {
continue;
}
- p = ngx_copy(p, h[i]->value.data, h[i]->value.len);
+ p = ngx_copy(p, th->value.data, th->value.len);
- if (p == end) {
+ if (th->next == NULL) {
break;
}
@@ -1102,8 +1095,8 @@ ngx_http_variable_cookie(ngx_http_request_t *r, ngx_http_variable_value_t *v,
s.len = name->len - (sizeof("cookie_") - 1);
s.data = name->data + sizeof("cookie_") - 1;
- if (ngx_http_parse_multi_header_lines(&r->headers_in.cookies, &s, &cookie)
- == NGX_DECLINED)
+ if (ngx_http_parse_multi_header_lines(r, r->headers_in.cookie, &s, &cookie)
+ == NULL)
{
v->not_found = 1;
return NGX_OK;