-
Notifications
You must be signed in to change notification settings - Fork 582
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
optimization parseIP in xff #1915
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #1915 +/- ##
==========================================
+ Coverage 35.91% 43.74% +7.83%
==========================================
Files 69 78 +9
Lines 11576 12479 +903
==========================================
+ Hits 4157 5459 +1302
+ Misses 7104 6678 -426
- Partials 315 342 +27 🚀 New features to boost your workflow:
|
|
||
if from_header { | ||
source = strings.Trim(strings.Split(source, ",")[0], " ") | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
虽然可以用,但逻辑上是怪怪的,为什么 fromHeader
就需要先 split,来自别的地方就不需要呢?还是说逻辑上是因为某些来源的数据可能会包含多个值,需要做 split。是不是外部传一个 separator 更合适?如果separator 为空,就不做 split。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
按照之前代码逻辑也是只有从Header中获取的ip才进行split https://github.com/alibaba/higress/pull/1915/files#diff-7c4a88bf97556c8363af8dc954fe2bfa077fc5b0122a4349e6e52c5a5be5eee1L102-L106
其实应该是只有xff才支持多ip,需要做split操作,理论上remontAddr 和 real-ip 都不支持多ip(real-ip不是标准该规范)
https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Headers/X-Forwarded-For
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Ⅰ. Describe what this PR did
optimization parseIP in xff
xff 分割符为 [英文逗号+空格],应该在提取后做trim操作(取第一个值其实理论没有问题)
parseIP函数中未支持多ip的处理,原有test case5中
127.0.0.1:12,[fe80::14d5:8aff:fed9:2114]:123
是正好第一个ip带了端口才通过,如果是127.0.0.1,[fe80::14d5:8aff:fed9:2114]:123
的话就会获取到127.0.0.1,[fe80
的结果Ⅱ. Does this pull request fix one issue?
Ⅲ. Why don't you add test cases (unit test/integration test)?
Ⅳ. Describe how to verify it
Ⅴ. Special notes for reviews