Open
Conversation
r.Header.Set simply overwrites the values. The expected public IP should be the first public IP encountered.
When we use Header.Get only the first entry is fetched. Per https://golang.org/src/net/http/request.go, when there are multiple entries of the same header, accessing the map directly allows us to get those multiple entries in an array. // Header contains the request header fields either received // by the server or to be sent by the client. // // If a server received a request with header lines, // // Host: example.com // accept-encoding: gzip, deflate // Accept-Language: en-us // fOO: Bar // foo: two // // then // // Header = map[string][]string{ // "Accept-Encoding": {"gzip, deflate"}, // "Accept-Language": {"en-us"}, // "Foo": {"Bar", "two"},
XFF can contain IP1,IP2,IP3 XFF can contain IP1, IP2 (note the space)
feat: Support multiple XFF headers
Author
|
@tomasen could you help review? thanks. |
|
This PR addresses all the concerns in #5 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This is to add support/fix bugs for having multiple X-Forwarded-For entries.
The commit message has details of the implementations.
There is a bug on the test case where "X-Forwarded-For" headers were not added (but were replaced instead):
master...RobinNil:master#diff-ffc776942d64deeeecf0f5ff91c039bfL55