comparison src/http/ngx_http_variables.c @ 8025:c263f9ffa1fd

All non-unique input headers are now linked lists. The ngx_http_process_multi_header_lines() function is removed, as it is exactly equivalent to ngx_http_process_header_line(). Similarly, ngx_http_variable_header() is used instead of ngx_http_variable_headers().
author Maxim Dounin <mdounin@mdounin.ru>
date Mon, 30 May 2022 21:25:35 +0300
parents ef6a3a99a81a
children cca4c8a715de
comparison
equal deleted inserted replaced
8024:ef6a3a99a81a 8025:c263f9ffa1fd
24 ngx_http_variable_value_t *v, uintptr_t data); 24 ngx_http_variable_value_t *v, uintptr_t data);
25 static ngx_int_t ngx_http_variable_header(ngx_http_request_t *r, 25 static ngx_int_t ngx_http_variable_header(ngx_http_request_t *r,
26 ngx_http_variable_value_t *v, uintptr_t data); 26 ngx_http_variable_value_t *v, uintptr_t data);
27 27
28 static ngx_int_t ngx_http_variable_cookies(ngx_http_request_t *r, 28 static ngx_int_t ngx_http_variable_cookies(ngx_http_request_t *r,
29 ngx_http_variable_value_t *v, uintptr_t data);
30 static ngx_int_t ngx_http_variable_headers(ngx_http_request_t *r,
31 ngx_http_variable_value_t *v, uintptr_t data); 29 ngx_http_variable_value_t *v, uintptr_t data);
32 static ngx_int_t ngx_http_variable_headers_internal(ngx_http_request_t *r, 30 static ngx_int_t ngx_http_variable_headers_internal(ngx_http_request_t *r,
33 ngx_http_variable_value_t *v, uintptr_t data, u_char sep); 31 ngx_http_variable_value_t *v, uintptr_t data, u_char sep);
34 32
35 static ngx_int_t ngx_http_variable_unknown_header_in(ngx_http_request_t *r, 33 static ngx_int_t ngx_http_variable_unknown_header_in(ngx_http_request_t *r,
176 { ngx_string("http_via"), NULL, ngx_http_variable_header, 174 { ngx_string("http_via"), NULL, ngx_http_variable_header,
177 offsetof(ngx_http_request_t, headers_in.via), 0, 0 }, 175 offsetof(ngx_http_request_t, headers_in.via), 0, 0 },
178 #endif 176 #endif
179 177
180 #if (NGX_HTTP_X_FORWARDED_FOR) 178 #if (NGX_HTTP_X_FORWARDED_FOR)
181 { ngx_string("http_x_forwarded_for"), NULL, ngx_http_variable_headers, 179 { ngx_string("http_x_forwarded_for"), NULL, ngx_http_variable_header,
182 offsetof(ngx_http_request_t, headers_in.x_forwarded_for), 0, 0 }, 180 offsetof(ngx_http_request_t, headers_in.x_forwarded_for), 0, 0 },
183 #endif 181 #endif
184 182
185 { ngx_string("http_cookie"), NULL, ngx_http_variable_cookies, 183 { ngx_string("http_cookie"), NULL, ngx_http_variable_cookies,
186 offsetof(ngx_http_request_t, headers_in.cookie), 0, 0 }, 184 offsetof(ngx_http_request_t, headers_in.cookie), 0, 0 },
325 ngx_http_variable_sent_keep_alive, 0, 0, 0 }, 323 ngx_http_variable_sent_keep_alive, 0, 0, 0 },
326 324
327 { ngx_string("sent_http_transfer_encoding"), NULL, 325 { ngx_string("sent_http_transfer_encoding"), NULL,
328 ngx_http_variable_sent_transfer_encoding, 0, 0, 0 }, 326 ngx_http_variable_sent_transfer_encoding, 0, 0, 0 },
329 327
330 { ngx_string("sent_http_cache_control"), NULL, ngx_http_variable_headers, 328 { ngx_string("sent_http_cache_control"), NULL, ngx_http_variable_header,
331 offsetof(ngx_http_request_t, headers_out.cache_control), 0, 0 }, 329 offsetof(ngx_http_request_t, headers_out.cache_control), 0, 0 },
332 330
333 { ngx_string("sent_http_link"), NULL, ngx_http_variable_headers, 331 { ngx_string("sent_http_link"), NULL, ngx_http_variable_header,
334 offsetof(ngx_http_request_t, headers_out.link), 0, 0 }, 332 offsetof(ngx_http_request_t, headers_out.link), 0, 0 },
335 333
336 { ngx_string("limit_rate"), ngx_http_variable_set_limit_rate, 334 { ngx_string("limit_rate"), ngx_http_variable_set_limit_rate,
337 ngx_http_variable_request_get_size, 335 ngx_http_variable_request_get_size,
338 offsetof(ngx_http_request_t, limit_rate), 336 offsetof(ngx_http_request_t, limit_rate),
805 803
806 static ngx_int_t 804 static ngx_int_t
807 ngx_http_variable_header(ngx_http_request_t *r, ngx_http_variable_value_t *v, 805 ngx_http_variable_header(ngx_http_request_t *r, ngx_http_variable_value_t *v,
808 uintptr_t data) 806 uintptr_t data)
809 { 807 {
810 ngx_table_elt_t *h; 808 return ngx_http_variable_headers_internal(r, v, data, ',');
811
812 h = *(ngx_table_elt_t **) ((char *) r + data);
813
814 if (h) {
815 v->len = h->value.len;
816 v->valid = 1;
817 v->no_cacheable = 0;
818 v->not_found = 0;
819 v->data = h->value.data;
820
821 } else {
822 v->not_found = 1;
823 }
824
825 return NGX_OK;
826 } 809 }
827 810
828 811
829 static ngx_int_t 812 static ngx_int_t
830 ngx_http_variable_cookies(ngx_http_request_t *r, 813 ngx_http_variable_cookies(ngx_http_request_t *r,
831 ngx_http_variable_value_t *v, uintptr_t data) 814 ngx_http_variable_value_t *v, uintptr_t data)
832 { 815 {
833 return ngx_http_variable_headers_internal(r, v, data, ';'); 816 return ngx_http_variable_headers_internal(r, v, data, ';');
834 }
835
836
837 static ngx_int_t
838 ngx_http_variable_headers(ngx_http_request_t *r,
839 ngx_http_variable_value_t *v, uintptr_t data)
840 {
841 return ngx_http_variable_headers_internal(r, v, data, ',');
842 } 817 }
843 818
844 819
845 static ngx_int_t 820 static ngx_int_t
846 ngx_http_variable_headers_internal(ngx_http_request_t *r, 821 ngx_http_variable_headers_internal(ngx_http_request_t *r,