Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[backend] extract correct host from the backend endpoint #267

Merged
merged 1 commit into from
Feb 21, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
* Danger bot to check for consistency in Pull Requests [PR #265](https://github.com/3scale/apicast/pull/265)
* Start local caching DNS server in the container [PR #260](https://github.com/3scale/apicast/pull/260)
* Management API to show the DNS cache [PR #260](https://github.com/3scale/apicast/pull/260)
* Extract correct Host header from the backend endpoint when backend host not provided [PR #267](https://github.com/3scale/apicast/pull/267)

## [3.0.0-alpha2] - 2017-02-06

Expand Down
4 changes: 1 addition & 3 deletions apicast/src/proxy.lua
Original file line number Diff line number Diff line change
Expand Up @@ -300,8 +300,6 @@ function _M:set_backend_upstream(service)

ngx.var.backend_authentication_type = service.backend_authentication.type
ngx.var.backend_authentication_value = service.backend_authentication.value
ngx.var.backend_host = service.backend.host or ngx.var.backend_host

ngx.var.version = self.configuration.version

-- set backend
Expand All @@ -317,7 +315,7 @@ function _M:set_backend_upstream(service)
ngx.ctx.backend_upstream = backend_upstream

ngx.var.backend_endpoint = scheme .. '://backend_upstream' .. path

ngx.var.backend_host = service.backend.host or server or ngx.var.backend_host
end

function _M:call(host)
Expand Down
58 changes: 58 additions & 0 deletions t/003-apicast.t
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ $ENV{TEST_NGINX_UPSTREAM_CONFIG} = "$apicast/http.d/upstream.conf";
$ENV{TEST_NGINX_BACKEND_CONFIG} = "$apicast/conf.d/backend.conf";
$ENV{TEST_NGINX_APICAST_CONFIG} = "$apicast/conf.d/apicast.conf";

require("t/dns.pl");

log_level('debug');
repeat_each(2);
no_root_location();
Expand Down Expand Up @@ -459,3 +461,59 @@ all ok
--- response_headers
X-3scale-matched-rules: /
X-3scale-usage: usage%5Bhits%5D=2
=== TEST 14: uses endpoint host as Host header
when connecting to the backend
--- main_config
env RESOLVER=127.0.0.1:1953;
--- http_config
include $TEST_NGINX_UPSTREAM_CONFIG;
lua_package_path "$TEST_NGINX_LUA_PATH";
init_by_lua_block {
require('proxy').configure({
services = {
{
id = 42,
backend_version = 1,
backend_authentication_type = 'service_token',
backend_authentication_value = 'service-token',
proxy = {
api_backend = "http://127.0.0.1:$TEST_NGINX_SERVER_PORT/api/",
backend = {
endpoint = 'http://localhost.example.com:$TEST_NGINX_SERVER_PORT'
},
proxy_rules = {
{ pattern = '/', http_method = 'GET', metric_system_name = 'hits', delta = 2 }
}
}
},
}
})
}
--- config
include $TEST_NGINX_APICAST_CONFIG;
location /api/ {
echo "all ok";
}
location /transactions/authrep.xml {
content_by_lua_block {
if ngx.var.host == 'localhost.example.com' then
ngx.exit(200)
else
ngx.exit(404)
end
}
}
--- request
GET /t?user_key=val
--- response_body
all ok
--- error_code: 200
--- udp_listen: 1953
--- udp_reply eval
$::dns->("localhost.example.com", "127.0.0.1")
--- no_error_log
[error]