Permalink
Browse files

bugfix: more_set_input_headers did not completely override the existi…

…ng request header with multiple values. thanks Aviram Cohen for the report.
  • Loading branch information...
1 parent bb92718 commit 540c6770fa57a0fd2ed2ad2386a569192ac983d4 @agentzh agentzh committed Dec 12, 2013
Showing with 50 additions and 5 deletions.
  1. +11 −3 src/ngx_http_headers_more_headers_in.c
  2. +27 −2 t/input.t
  3. +12 −0 valgrind.suppress
@@ -173,13 +173,15 @@ ngx_http_set_header_helper(ngx_http_request_t *r,
ngx_http_headers_more_header_val_t *hv, ngx_str_t *value,
ngx_table_elt_t **output_header)
{
- ngx_table_elt_t *h;
+ ngx_table_elt_t *h, *matched;
ngx_list_part_t *part;
ngx_uint_t i;
ngx_uint_t rc;
dd_enter();
+ matched = NULL;
+
retry:
part = &r->headers_in.headers.part;
h = part->elts;
@@ -201,7 +203,7 @@ ngx_http_set_header_helper(ngx_http_request_t *r,
&& ngx_strncasecmp(h[i].key.data, hv->key.data,
h[i].key.len) == 0)
{
- if (value->len == 0) {
+ if (value->len == 0 || (matched && matched != &h[i])) {
h[i].hash = 0;
rc = ngx_http_headers_more_rm_header_helper(
@@ -230,10 +232,16 @@ ngx_http_set_header_helper(ngx_http_request_t *r,
dd("setting existing builtin input header");
}
- return NGX_OK;
+ if (matched == NULL) {
+ matched = &h[i];
+ }
}
}
+ if (matched) {
+ return NGX_OK;
+ }
+
if (value->len == 0 || hv->replace) {
return NGX_OK;
}
View
@@ -5,7 +5,7 @@ use Test::Nginx::Socket; # 'no_plan';
repeat_each(2);
-plan tests => repeat_each() * 102;
+plan tests => repeat_each() * 105;
no_long_string();
#no_diff;
@@ -1102,7 +1102,7 @@ http_host var: agentZH.org:1984
-=== TEST 44: clear all and re-insert
+=== TEST 42: clear all and re-insert
--- config
location = /t {
more_clear_input_headers Host Connection Cache-Control Accept
@@ -1141,3 +1141,28 @@ ok
--- no_error_log
[error]
+
+
+=== TEST 43: more_set_input_header does not override request headers with multiple values
+--- config
+ #lua_code_cache off;
+ location = /t {
+ more_set_input_headers "AAA: 111";
+
+ content_by_lua '
+ local headers = ngx.req.get_headers()
+ ngx.say(headers["AAA"])
+ ';
+ }
+--- request
+GET /t
+--- more_headers
+AAA: 123
+AAA: 456
+AAA: 678
+
+--- response_body
+111
+--- no_error_log
+[error]
+
View
@@ -1,4 +1,16 @@
{
+ <insert_a_suppression_name_here>
+ Memcheck:Cond
+ fun:lj_str_new
+ fun:lua_pushlstring
+}
+{
+ <insert_a_suppression_name_here>
+ Memcheck:Addr4
+ fun:lj_str_new
+ fun:lua_pushlstring
+}
+{
<insert_a_suppression_name_here>
Memcheck:Leak
fun:malloc

0 comments on commit 540c677

Please sign in to comment.