Skip to content

Support multiple IP addresses for http_x_forwarded_for#45

Open
conradolega wants to merge 1 commit intosatyrius:masterfrom
conradolega:fix-http-forwarded-for
Open

Support multiple IP addresses for http_x_forwarded_for#45
conradolega wants to merge 1 commit intosatyrius:masterfrom
conradolega:fix-http-forwarded-for

Conversation

@conradolega
Copy link

This improves upon #37 by fixing some errors, and rebases it on top of master.

I've also updated the CI job to run against 1.12. It should also pass against Go's tip version.

Fixes #36.

@conradolega conradolega force-pushed the fix-http-forwarded-for branch from 5cf8f83 to 8e4ca23 Compare November 26, 2019 23:45
gonx "../.."
"flag"
"fmt"
gonx "github.com/satyrius/gonx"
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why did you change it from relative path? It was very convenient for development.

- 1.3
- 1.4
- 1.5
- 1.12
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sort versions alphabetically plz

parser.go Outdated

func getSpecialNginxRegexes() map[string]string {
return map[string]string{
"http_x_forwarded_for": `[^, ]*(?:, [^, ]+)*`}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The formatting looks off on those lines above. Can you double check gofmt plz?

} else {
re = strings.Replace(re, field[2]+field[4], regexp.QuoteMeta(field[1])+"(?P<"+field[2]+">[^"+terminateChar+"]*)"+regexp.QuoteMeta(field[3]+field[4]), 1)
}
}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the patch above, please, consider adding more comments around to explain what's going on.

if specialRegex, found := specialNginxRegexes[field[2]]; found {
re = strings.Replace(re, field[2]+field[4], regexp.QuoteMeta(field[1])+"(?P<"+field[2]+">"+specialRegex+")"+regexp.QuoteMeta(field[3])+field[4], 1)
} else {
re = strings.Replace(re, field[2]+field[4], regexp.QuoteMeta(field[1])+"(?P<"+field[2]+">[^"+terminateChar+"]*)"+regexp.QuoteMeta(field[3]+field[4]), 1)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like code duplication, please, make it more readable.

@satyrius
Copy link
Owner

satyrius commented Sep 5, 2022

@conradolega are you interested in wrapping this up?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Space between IP Addresses in $http_x_forwarded_for

2 participants