Skip to content

Commit

Permalink
fix(api-router) support routing requests without Host header for HTTP…
Browse files Browse the repository at this point in the history
…/1.0

Port of cd8b4df to the legacy API
router (backwards-compatible router for APIs).

Fix #3435 
From #3438
  • Loading branch information
thibaultcha authored May 8, 2018
1 parent 31d9ed7 commit 9edbb1d
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
2 changes: 1 addition & 1 deletion kong/api_router.lua
Original file line number Diff line number Diff line change
Expand Up @@ -837,7 +837,7 @@ function _M.new(apis)
end
end

local req_host = ngx.var.http_host
local req_host = ngx.var.http_host or ""

local match_t = find_api(method, uri, req_host, ngx)
if not match_t then
Expand Down
19 changes: 19 additions & 0 deletions spec-old-api/01-unit/010-router_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -921,6 +921,25 @@ describe("Router", function()
return _ngx
end

it("[uri + empty host]", function()
-- uri only (no Host)
-- Supported for HTTP/1.0 requests without a Host header
-- Regression for https://github.com/Kong/kong/issues/3435
local use_case_apis = {
{
name = "api-1",
uris = { "/my-api" },
upstream_url = "http://example.org",
},
}

local router = assert(Router.new(use_case_apis))

local _ngx = mock_ngx("GET", "/my-api", { ["host"] = nil })
local match_t = router.exec(_ngx)
assert.same(use_case_apis[1], match_t.api)
end)

it("returns parsed upstream_url + upstream_uri", function()
local use_case_apis = {
{
Expand Down

0 comments on commit 9edbb1d

Please sign in to comment.