From 5164bc4a8ec2f87c803f513df317e9dabf8108d7 Mon Sep 17 00:00:00 2001 From: thefosk Date: Fri, 6 Nov 2015 13:56:36 -0800 Subject: [PATCH] hotfix(resolver) avoid URL decoding in URI proxying --- kong/resolver/access.lua | 3 ++- spec/integration/proxy/api_resolver_spec.lua | 20 +++++++++++++++++++- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/kong/resolver/access.lua b/kong/resolver/access.lua index bdfcd452370..3001f9172f1 100644 --- a/kong/resolver/access.lua +++ b/kong/resolver/access.lua @@ -194,7 +194,8 @@ local function find_api(uri) end function _M.execute(conf) - local uri = ngx.var.uri + local uri = stringy.split(ngx.var.request_uri, "?")[1] + local err, api, hosts, strip_request_path_pattern = find_api(uri) if err then return responses.send_HTTP_INTERNAL_SERVER_ERROR(err) diff --git a/spec/integration/proxy/api_resolver_spec.lua b/spec/integration/proxy/api_resolver_spec.lua index a200b3840fd..6a9d608a3b5 100644 --- a/spec/integration/proxy/api_resolver_spec.lua +++ b/spec/integration/proxy/api_resolver_spec.lua @@ -36,7 +36,8 @@ describe("Resolver", function() {name = "tests-wildcard-subdomain", upstream_url = "http://mockbin.com/status/200", request_host = "*.wildcard.com"}, {name = "tests-wildcard-subdomain-2", upstream_url = "http://mockbin.com/status/201", request_host = "wildcard.*"}, {name = "tests-preserve-host", request_host = "httpbin-nopreserve.com", upstream_url = "http://httpbin.org"}, - {name = "tests-preserve-host-2", request_host = "httpbin-preserve.com", upstream_url = "http://httpbin.org", preserve_host = true} + {name = "tests-preserve-host-2", request_host = "httpbin-preserve.com", upstream_url = "http://httpbin.org", preserve_host = true}, + {name = "tests-uri", request_host = "mockbin-uri.com", upstream_url = "http://mockbin.org"} }, plugin = { {name = "key-auth", config = {key_names = {"apikey"} }, __api = 2} @@ -50,6 +51,22 @@ describe("Resolver", function() spec_helper.stop_kong() end) + describe("Test URI", function() + + it("should URL decode the URI with querystring", function() + local response, status = http_client.get(spec_helper.STUB_GET_URL.."/hello%2F", { hello = "world"}, {host = "mockbin-uri.com"}) + assert.equal(200, status) + assert.equal("http://mockbin.org/request/hello%2f?hello=world", cjson.decode(response).url) + end) + + it("should URL decode the URI without querystring", function() + local response, status = http_client.get(spec_helper.STUB_GET_URL.."/hello%2F", nil, {host = "mockbin-uri.com"}) + assert.equal(200, status) + assert.equal("http://mockbin.org/request/hello%2f", cjson.decode(response).url) + end) + + end) + describe("Inexistent API", function() it("should return Not Found when the API is not in Kong", function() @@ -216,4 +233,5 @@ describe("Resolver", function() assert.equal("httpbin-preserve.com", parsed_response.headers["Host"]) end) end) + end)