Skip to content

Commit

Permalink
Fix Nginx::Headers_in[] returns wrong value. Fixed matsumotory#471.
Browse files Browse the repository at this point in the history
  • Loading branch information
yyamano committed Aug 16, 2020
1 parent 324d5a0 commit 14ed12d
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/http/ngx_http_mruby_request.c
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,8 @@ static mrb_value ngx_mrb_get_request_header(mrb_state *mrb, ngx_list_t *headers,
i = 0;
}

if (ngx_strncasecmp(header[i].key.data, key, key_len) == 0) {
if (header[i].key.len == key_len &&
ngx_strncasecmp(header[i].key.data, key, key_len) == 0) {
mrb_ary_push(mrb, ary, mrb_str_new(mrb, (const char *)header[i].value.data, header[i].value.len));
}
}
Expand Down
8 changes: 8 additions & 0 deletions test/conf/nginx.conf
Original file line number Diff line number Diff line change
Expand Up @@ -928,6 +928,14 @@ http {
end
';
}

location /issue-471 {
mruby_content_handler_code '
h = Nginx::Headers_in.new
Nginx.rputs h["X-Foo"]
Nginx.rputs h["X-Foo-Bar"]
';
}
}

server {
Expand Down
5 changes: 5 additions & 0 deletions test/t/ngx_mruby.rb
Original file line number Diff line number Diff line change
Expand Up @@ -780,6 +780,11 @@ def _run
res = HttpRequest.new.get base + '/iv_init_worker'
t.assert_equal 'true', res["body"]
end

t.assert('ngx_mruby - BUG: header issue 471', 'location /issue-471') do
res = HttpRequest.new.get base + '/issue-471', nil, {"X-Foo" => "foo", "X-Foo-Bar" => "bar"}
t.assert_equal 'foobar', res["body"]
end
end


Expand Down

0 comments on commit 14ed12d

Please sign in to comment.