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/08/19 03:38:32 UTC
[GitHub] [apisix] spacewander opened a new pull request #4852: feat(real-ip): add special handling to X-Forwarded-For
spacewander opened a new pull request #4852:
URL: https://github.com/apache/apisix/pull/4852
This logic is the same with Nginx's nginx_realip_module.
Signed-off-by: spacewander <sp...@gmail.com>
### What this PR does / why we need it:
<!--- Why is this change required? What problem does it solve? -->
<!--- If it fixes an open issue, please link to the issue here. -->
### Pre-submission checklist:
* [x] Did you explain what problem does this PR solve? Or what new features have been added?
* [x] Have you added corresponding test cases?
* [ ] Have you modified the corresponding document?
* [ ] Is this PR backward compatible? **If it is not backward compatible, please discuss on the [mailing list](https://github.com/apache/apisix/tree/master#community) first**
--
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
[GitHub] [apisix] spacewander commented on a change in pull request #4852: feat(real-ip): add special handling to X-Forwarded-For
Posted by GitBox <gi...@apache.org>.
spacewander commented on a change in pull request #4852:
URL: https://github.com/apache/apisix/pull/4852#discussion_r692038139
##########
File path: apisix/plugins/real-ip.lua
##########
@@ -49,6 +50,30 @@ end
local function get_addr(conf, ctx)
+ if conf.source == "http_x_forwarded_for" then
+ -- use the last address from X-Forwarded-For header
+ local addrs = core.request.header(ctx, "X-Forwarded-For")
+ if not addrs then
+ return nil
+ end
+
+ if type(addrs) == "table" then
+ addrs = addrs[#addrs]
+ end
+
+ local idx = core.string.rfind_char(addrs, ",")
+ if not idx then
+ return addrs
+ end
+
+ for i = idx + 1, #addrs do
+ if str_byte(addrs, i) == str_byte(" ") then
+ idx = idx + 1
+ end
Review comment:
Good catch.
--
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
[GitHub] [apisix] spacewander merged pull request #4852: feat(real-ip): add special handling to X-Forwarded-For
Posted by GitBox <gi...@apache.org>.
spacewander merged pull request #4852:
URL: https://github.com/apache/apisix/pull/4852
--
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
[GitHub] [apisix] tokers commented on a change in pull request #4852: feat(real-ip): add special handling to X-Forwarded-For
Posted by GitBox <gi...@apache.org>.
tokers commented on a change in pull request #4852:
URL: https://github.com/apache/apisix/pull/4852#discussion_r692030499
##########
File path: apisix/plugins/real-ip.lua
##########
@@ -49,6 +50,30 @@ end
local function get_addr(conf, ctx)
+ if conf.source == "http_x_forwarded_for" then
+ -- use the last address from X-Forwarded-For header
+ local addrs = core.request.header(ctx, "X-Forwarded-For")
+ if not addrs then
+ return nil
+ end
+
+ if type(addrs) == "table" then
+ addrs = addrs[#addrs]
+ end
+
+ local idx = core.string.rfind_char(addrs, ",")
+ if not idx then
+ return addrs
+ end
+
+ for i = idx + 1, #addrs do
+ if str_byte(addrs, i) == str_byte(" ") then
+ idx = idx + 1
+ end
Review comment:
Else break?
--
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