Skip to content

Commit

Permalink
resolver: polishing pattern characters stripping
Browse files Browse the repository at this point in the history
  • Loading branch information
thibaultcha committed Jul 27, 2015
1 parent c1e4883 commit 26e72da
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
5 changes: 3 additions & 2 deletions kong/resolver/access.lua
Original file line number Diff line number Diff line change
Expand Up @@ -162,10 +162,11 @@ function _M.execute(conf)
}
end

-- If API was retrieved by path
-- If API was retrieved by path and the path needs to be stripped
if by_path and api.strip_path then
-- Replace `/path` with `path`, and then prefix with a `/`
-- Or replace `/path/foo` with `/foo`, and then do not prefix with `/`.
-- or replace `/path/foo` with `/foo`, and then do not prefix with `/`.
-- Handles pattern-specific characters if any.
local escaped_path = api.path:gsub("[%(%)%.%%%+%-%*%?%[%]%^%$]", function(c) return "%" .. c end)
request_uri = string.gsub(request_uri, escaped_path, "")
if string.sub(request_uri, 0, 1) ~= "/" then
Expand Down
6 changes: 3 additions & 3 deletions spec/integration/proxy/api_resolver_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ describe("Resolver", function()
{name = "tests host resolver 2", public_dns = "mockbin-auth.com", target_url = "http://mockbin.com"},
{name = "tests path resolver", target_url = "http://mockbin.com", path = "/status/"},
{name = "tests stripped path resolver", target_url = "http://mockbin.com", path = "/mockbin/", strip_path = true},
{name = "tests stripped path resolver with magic", target_url = "http://mockbin.com", path = "/mockbin-with-magic/", strip_path = true},
{name = "tests stripped path resolver with pattern characters", target_url = "http://mockbin.com", path = "/mockbin-with-pattern/", strip_path = true},
{name = "tests deep path resolver", target_url = "http://mockbin.com", path = "/deep/path/", strip_path = true},
{name = "tests wildcard subdomain", target_url = "http://mockbin.com/status/200", public_dns = "*.wildcard.com"},
{name = "tests wildcard subdomain 2", target_url = "http://mockbin.com/status/201", public_dns = "wildcard.*"}
Expand Down Expand Up @@ -163,8 +163,8 @@ describe("Resolver", function()
assert.equal("http://mockbin.com/request", body.url)
end)

it("should proxy and strip the path if `strip_path` is true if path has magic characters", function()
local response, status = http_client.get(spec_helper.PROXY_URL.."/mockbin-with-magic/request")
it("should proxy and strip the path if `strip_path` is true if path has pattern characters", function()
local response, status = http_client.get(spec_helper.PROXY_URL.."/mockbin-with-pattern/request")
assert.equal(200, status)
local body = cjson.decode(response)
assert.equal("http://mockbin.com/request", body.url)
Expand Down

0 comments on commit 26e72da

Please sign in to comment.