Skip to content

Commit

Permalink
fix: proxy_set_header Host $host may lose port info (#2079)
Browse files Browse the repository at this point in the history
  • Loading branch information
halfcrazy authored Jan 27, 2021
1 parent ea8eef8 commit 8d61d31
Show file tree
Hide file tree
Showing 6 changed files with 81 additions and 9 deletions.
4 changes: 2 additions & 2 deletions apisix/cli/ngx_tpl.lua
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ http {
# admin configuration snippet ends
set $upstream_scheme 'http';
set $upstream_host $host;
set $upstream_host $http_host;
set $upstream_uri '';
location /apisix/admin {
Expand Down Expand Up @@ -410,7 +410,7 @@ http {
# http server configuration snippet ends
set $upstream_scheme 'http';
set $upstream_host $host;
set $upstream_host $http_host;
set $upstream_uri '';
set $ctx_ref '';
Expand Down
2 changes: 1 addition & 1 deletion benchmark/fake-apisix/conf/nginx.conf
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ http {

location / {
set $upstream_scheme 'http';
set $upstream_host $host;
set $upstream_host $http_host;
set $upstream_upgrade '';
set $upstream_connection '';
set $upstream_uri '';
Expand Down
2 changes: 1 addition & 1 deletion t/APISIX.pm
Original file line number Diff line number Diff line change
Expand Up @@ -488,7 +488,7 @@ _EOC_
}
set \$upstream_scheme 'http';
set \$upstream_host \$host;
set \$upstream_host \$http_host;
set \$upstream_uri '';
set \$ctx_ref '';
set \$dubbo_service_name '';
Expand Down
72 changes: 72 additions & 0 deletions t/node/http_host.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
use t::APISIX 'no_plan';

repeat_each(1);
log_level('info');
worker_connections(256);
no_root_location();
no_shuffle();

run_tests();

__DATA__
=== TEST 1: set route(id: 1)
--- config
location /t {
content_by_lua_block {
local t = require("lib.test_admin").test
local code, body = t('/apisix/admin/routes/1',
ngx.HTTP_PUT,
[[{
"uri": "/uri",
"upstream": {
"nodes": {
"127.0.0.1:1980": 1
},
"type": "roundrobin"
}
}]]
)
if code >= 300 then
ngx.status = code
end
ngx.say(body)
}
}
--- request
GET /t
--- response_body
passed
--- no_error_log
[error]
=== TEST 2: hit routes
--- request
GET /uri
--- more_headers
Host: foo.com:1984
--- response_body
uri: /uri
host: foo.com:1984
x-real-ip: 127.0.0.1
--- no_error_log
[error]
6 changes: 3 additions & 3 deletions t/plugin/hmac-auth.t
Original file line number Diff line number Diff line change
Expand Up @@ -1016,7 +1016,7 @@ GET /t
uri: /uri
content-length: 52
content-type: application/x-www-form-urlencoded
host: 127.0.0.1
host: 127.0.0.1:1984
x-custom-header-a: asld$%dfasf
x-custom-header-b: 23879fmsldfk
x-hmac-access-key: my-access-key4
Expand Down Expand Up @@ -1131,7 +1131,7 @@ GET /t
uri: /uri
content-length: 52
content-type: application/x-www-form-urlencoded
host: 127.0.0.1
host: 127.0.0.1:1984
x-custom-header-a: asld$%dfasf
x-custom-header-b: 23879fmsldfk
x-hmac-access-key: my-access-key4
Expand Down Expand Up @@ -1246,7 +1246,7 @@ GET /t
uri: /uri
content-length: 52
content-type: application/x-www-form-urlencoded
host: 127.0.0.1
host: 127.0.0.1:1984
x-custom-header-a: asld$%dfasf
x-custom-header-b: 23879fmsldfk
x-hmac-access-key: my-access-key4
Expand Down
4 changes: 2 additions & 2 deletions t/plugin/openid-connect.t
Original file line number Diff line number Diff line change
Expand Up @@ -474,7 +474,7 @@ GET /t
--- response_body_like
uri: /uri
cookie: .*
host: 127.0.0.1
host: 127.0.0.1:1984
user-agent: .*
x-access-token: ey.*
x-id-token: ey.*
Expand Down Expand Up @@ -768,7 +768,7 @@ GET /t
uri: /uri
authorization: Bearer ey.*
cookie: .*
host: 127.0.0.1
host: 127.0.0.1:1984
user-agent: .*
x-real-ip: 127.0.0.1
--- no_error_log
Expand Down

0 comments on commit 8d61d31

Please sign in to comment.