Add x-forwarded-url to request headers (#281)
diff --git a/scripts/lua/routing.lua b/scripts/lua/routing.lua
index 6d20c61..445d08e 100644
--- a/scripts/lua/routing.lua
+++ b/scripts/lua/routing.lua
@@ -87,6 +87,17 @@
end
-- Set backend upstream and uri
backendRouting.setRoute(opFields.backendUrl, gatewayPath)
+ -- Set gateway url as request header
+ local requestScheme = ngx.req.get_headers()["X-Forwarded-Proto"]
+ if requestScheme == nil or requestScheme == "" then
+ requestScheme = ngx.var.scheme
+ end
+ local requestUrl = utils.concatStrings({requestScheme, "://", ngx.var.host})
+ local prefix = ngx.req.get_headers()["X-Forwarded-Prefix"]
+ if prefix ~= nil and prefix ~= "" then
+ requestUrl = utils.concatStrings({requestUrl, prefix})
+ end
+ ngx.req.set_header("X-Forwarded-Url", utils.concatStrings({requestUrl, ngx.var.request_uri}))
-- Parse policies
if opFields.policies ~= nil then
parsePolicies(dataStore, opFields.policies, key)