From 996b73213fac40dfee347703a6333411de5d178c Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 7 May 2015 21:45:27 -0400 Subject: [PATCH] ref #192 ref #203 --- kong/resolver/access.lua | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/kong/resolver/access.lua b/kong/resolver/access.lua index a6f5f1c6590a..cb1a5822f7b9 100644 --- a/kong/resolver/access.lua +++ b/kong/resolver/access.lua @@ -38,9 +38,14 @@ end -- Retrieve the API from the Host that has been requested function _M.execute(conf) + local hosts = ngx.req.get_headers()["host"] -- Multiple "Host" can have been requested if type(hosts) == "string" then - hosts = { hosts } + if hosts == ngx.var.host..":"..ngx.var.server_port then + hosts = { stringy.split(ngx.var.request_uri, "/")[2] } + else + hosts = { hosts } + end elseif not hosts then hosts = {} end @@ -65,7 +70,12 @@ function _M.execute(conf) end -- Setting the backend URL for the proxy_pass directive - ngx.var.backend_url = get_backend_url(api)..ngx.var.request_uri + local hosts = ngx.req.get_headers()["host"] + if type(hosts) == "string" and hosts == ngx.var.host..":"..ngx.var.server_port then + ngx.var.backend_url = get_backend_url(api).."/"..table.concat(stringy.split(ngx.var.request_uri, "/"), ",", 3) + else + ngx.var.backend_url = get_backend_url(api)..ngx.var.request_uri + end ngx.req.set_header("host", get_host_from_url(ngx.var.backend_url))