comparison src/http/modules/ngx_http_proxy_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 2f443cac3f1e
children 2025aae94739
comparison
equal deleted inserted replaced
8023:08b3ea81ff5f 8024:ef6a3a99a81a
2557 2557
2558 static ngx_int_t 2558 static ngx_int_t
2559 ngx_http_proxy_add_x_forwarded_for_variable(ngx_http_request_t *r, 2559 ngx_http_proxy_add_x_forwarded_for_variable(ngx_http_request_t *r,
2560 ngx_http_variable_value_t *v, uintptr_t data) 2560 ngx_http_variable_value_t *v, uintptr_t data)
2561 { 2561 {
2562 size_t len; 2562 size_t len;
2563 u_char *p; 2563 u_char *p;
2564 ngx_uint_t i, n; 2564 ngx_table_elt_t *h, *xfwd;
2565 ngx_table_elt_t **h;
2566 2565
2567 v->valid = 1; 2566 v->valid = 1;
2568 v->no_cacheable = 0; 2567 v->no_cacheable = 0;
2569 v->not_found = 0; 2568 v->not_found = 0;
2570 2569
2571 n = r->headers_in.x_forwarded_for.nelts; 2570 xfwd = r->headers_in.x_forwarded_for;
2572 h = r->headers_in.x_forwarded_for.elts;
2573 2571
2574 len = 0; 2572 len = 0;
2575 2573
2576 for (i = 0; i < n; i++) { 2574 for (h = xfwd; h; h = h->next) {
2577 len += h[i]->value.len + sizeof(", ") - 1; 2575 len += h->value.len + sizeof(", ") - 1;
2578 } 2576 }
2579 2577
2580 if (len == 0) { 2578 if (len == 0) {
2581 v->len = r->connection->addr_text.len; 2579 v->len = r->connection->addr_text.len;
2582 v->data = r->connection->addr_text.data; 2580 v->data = r->connection->addr_text.data;
2591 } 2589 }
2592 2590
2593 v->len = len; 2591 v->len = len;
2594 v->data = p; 2592 v->data = p;
2595 2593
2596 for (i = 0; i < n; i++) { 2594 for (h = xfwd; h; h = h->next) {
2597 p = ngx_copy(p, h[i]->value.data, h[i]->value.len); 2595 p = ngx_copy(p, h->value.data, h->value.len);
2598 *p++ = ','; *p++ = ' '; 2596 *p++ = ','; *p++ = ' ';
2599 } 2597 }
2600 2598
2601 ngx_memcpy(p, r->connection->addr_text.data, r->connection->addr_text.len); 2599 ngx_memcpy(p, r->connection->addr_text.data, r->connection->addr_text.len);
2602 2600