Skip to content
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

Support multiple IP addresses for http_x_forwarded_for #45

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

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.

"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
@@ -19,6 +19,11 @@ type Parser struct {
regexp *regexp.Regexp
}

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