Skip to content

Instantly share code, notes, and snippets.

@p0pr0ck5
Created June 8, 2017 23:18
Show Gist options
  • Save p0pr0ck5/e742a478a8bfcaeabeefddafd54af947 to your computer and use it in GitHub Desktop.
Save p0pr0ck5/e742a478a8bfcaeabeefddafd54af947 to your computer and use it in GitHub Desktop.
diff --git a/kong/core/handler.lua b/kong/core/handler.lua
index 80bec19..1927adf 100644
--- a/kong/core/handler.lua
+++ b/kong/core/handler.lua
@@ -138,6 +138,8 @@ return {
var.upstream_host = host_header or
balancer_address.hostname..":"..balancer_address.port
+ var.has_query = var.request_uri:find("?", nil, true) and
+ var.is_args == "?" and "?" or ""
end,
-- Only executed if the `router` module found an API and allows nginx to proxy it.
after = function()
diff --git a/kong/templates/nginx_kong.lua b/kong/templates/nginx_kong.lua
index a2eb2f5..26eb525 100644
--- a/kong/templates/nginx_kong.lua
+++ b/kong/templates/nginx_kong.lua
@@ -109,6 +109,7 @@ server {
set $upstream_host nil;
set $upstream_scheme nil;
set $upstream_uri nil;
+ set $has_query nil;
rewrite_by_lua_block {
kong.rewrite()
@@ -129,7 +130,7 @@ server {
proxy_ssl_name $upstream_host;
- proxy_pass $upstream_scheme://kong_upstream$upstream_uri$is_args$args;
+ proxy_pass $upstream_scheme://kong_upstream$upstream_uri$has_query$args;
header_filter_by_lua_block {
kong.header_filter()
diff --git a/spec/02-integration/05-proxy/01-router_spec.lua b/spec/02-integration/05-proxy/01-router_spec.lua
index a8626b5..a3847d0 100644
--- a/spec/02-integration/05-proxy/01-router_spec.lua
+++ b/spec/02-integration/05-proxy/01-router_spec.lua
@@ -186,7 +186,7 @@ describe("Router", function()
assert.equal("world", json.args.hello)
end)
- it("does not proxy '$is_args' if URI does not contain arguments", function()
+ it("does proxy '$is_args' if URI does not contain arguments #o", function()
local res = assert(client:send {
method = "GET",
path = "/get?",
@@ -197,7 +197,7 @@ describe("Router", function()
local body = assert.res_status(200, res)
local json = cjson.decode(body)
- assert.matches("/get$", json.url)
+ assert.matches("/get%?$", json.url)
end)
end)
diff --git a/spec/fixtures/custom_nginx.template b/spec/fixtures/custom_nginx.template
index 3de15ab..e5f632b 100644
--- a/spec/fixtures/custom_nginx.template
+++ b/spec/fixtures/custom_nginx.template
@@ -106,6 +106,7 @@ http {
set $upstream_host nil;
set $upstream_scheme nil;
set $upstream_uri nil;
+ set $has_query nil;
access_by_lua_block {
kong.access()
@@ -122,7 +123,7 @@ http {
proxy_ssl_name $upstream_host;
- proxy_pass $upstream_scheme://kong_upstream$upstream_uri$is_args$args;
+ proxy_pass $upstream_scheme://kong_upstream$upstream_uri$has_query$args;
header_filter_by_lua_block {
kong.header_filter()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment