You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@apisix.apache.org by GitBox <gi...@apache.org> on 2021/11/03 01:36:11 UTC

[GitHub] [apisix] spacewander commented on a change in pull request #5367: feat: support overwrite X-Forwarded-*

spacewander commented on a change in pull request #5367:
URL: https://github.com/apache/apisix/pull/5367#discussion_r741566964



##########
File path: apisix/init.lua
##########
@@ -266,12 +266,21 @@ local function set_upstream_host(api_ctx, picked_server)
 end
 
 
+local upstream_proxy_headers = {
+    var_x_forwarded_proto = 'X-Forwarded-Proto',
+    var_x_forwarded_for = 'X-Forwarded-For',

Review comment:
       For X-Forwarded-For, we need to append the client's real-ip to it, see https://github.com/apache/apisix/blob/a0efeca194bcca58e62d73c0a19464f480a1b7c9/t/APISIX.pm#L698

##########
File path: apisix/init.lua
##########
@@ -266,12 +266,21 @@ local function set_upstream_host(api_ctx, picked_server)
 end
 
 
+local upstream_proxy_headers = {
+    var_x_forwarded_proto = 'X-Forwarded-Proto',
+    var_x_forwarded_for = 'X-Forwarded-For',
+    var_x_forwarded_host = 'X-Forwarded-Host',
+    var_x_forwarded_port = 'X-Forwarded-Port',
+}
+
 local function set_upstream_headers(api_ctx, picked_server)
     set_upstream_host(api_ctx, picked_server)
 
-    local hdr = core.request.header(api_ctx, "X-Forwarded-Proto")
-    if hdr then
-        api_ctx.var.var_x_forwarded_proto = hdr
+    for ngx_key, hdr_key in pairs(upstream_proxy_headers) do

Review comment:
       We can also remove https://github.com/apache/apisix/blob/a0efeca194bcca58e62d73c0a19464f480a1b7c9/apisix/cli/ngx_tpl.lua#L600 and https://github.com/apache/apisix/blob/a0efeca194bcca58e62d73c0a19464f480a1b7c9/t/APISIX.pm#L697




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org