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

feat: special case CloudFlare client IP addrs #148

Merged
merged 2 commits into from
Oct 6, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions httpbin/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@
return clientIP
}

// Special case Cloudflare for the value directly.
vanodevium marked this conversation as resolved.
Show resolved Hide resolved
if cfClientIP := r.Header.Get("CF-Connecting-IP"); cfClientIP != "" {
return cfClientIP
vanodevium marked this conversation as resolved.
Show resolved Hide resolved
}

Check warning on line 56 in httpbin/helpers.go

View check run for this annotation

Codecov / codecov/patch

httpbin/helpers.go#L55-L56

Added lines #L55 - L56 were not covered by tests

// Try to pull a reasonable value from the X-Forwarded-For header, if
// present, by taking the first entry in a comma-separated list of IPs.
if forwardedFor := r.Header.Get("X-Forwarded-For"); forwardedFor != "" {
Expand Down
Loading