aboutsummaryrefslogtreecommitdiffstats
path: root/vendor/github.com/gorilla/handlers/proxy_headers.go
diff options
context:
space:
mode:
authordependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>2023-11-06 01:20:46 +0000
committerTaras Madan <tarasmadan@google.com>2023-11-06 10:59:50 +0000
commit78fae24ecb7ff84a4eec0a96bb9a343c1a5e19aa (patch)
tree6fa22f6be1d55885661d53f0e5397cfc00ebb712 /vendor/github.com/gorilla/handlers/proxy_headers.go
parent1ac37bad9c41d00140a61a4a5dddc45a50ff4c62 (diff)
mod: do: bump github.com/gorilla/handlers from 1.5.1 to 1.5.2
Bumps [github.com/gorilla/handlers](https://github.com/gorilla/handlers) from 1.5.1 to 1.5.2. - [Release notes](https://github.com/gorilla/handlers/releases) - [Commits](https://github.com/gorilla/handlers/compare/v1.5.1...v1.5.2) --- updated-dependencies: - dependency-name: github.com/gorilla/handlers dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <support@github.com>
Diffstat (limited to 'vendor/github.com/gorilla/handlers/proxy_headers.go')
-rw-r--r--vendor/github.com/gorilla/handlers/proxy_headers.go16
1 files changed, 8 insertions, 8 deletions
diff --git a/vendor/github.com/gorilla/handlers/proxy_headers.go b/vendor/github.com/gorilla/handlers/proxy_headers.go
index ed939dcef..281d753e9 100644
--- a/vendor/github.com/gorilla/handlers/proxy_headers.go
+++ b/vendor/github.com/gorilla/handlers/proxy_headers.go
@@ -18,7 +18,7 @@ var (
var (
// RFC7239 defines a new "Forwarded: " header designed to replace the
// existing use of X-Forwarded-* headers.
- // e.g. Forwarded: for=192.0.2.60;proto=https;by=203.0.113.43
+ // e.g. Forwarded: for=192.0.2.60;proto=https;by=203.0.113.43.
forwarded = http.CanonicalHeaderKey("Forwarded")
// Allows for a sub-match of the first value after 'for=' to the next
// comma, semi-colon or space. The match is case-insensitive.
@@ -67,7 +67,9 @@ func ProxyHeaders(h http.Handler) http.Handler {
func getIP(r *http.Request) string {
var addr string
- if fwd := r.Header.Get(xForwardedFor); fwd != "" {
+ switch {
+ case r.Header.Get(xForwardedFor) != "":
+ fwd := r.Header.Get(xForwardedFor)
// Only grab the first (client) address. Note that '192.168.0.1,
// 10.1.1.1' is a valid key for X-Forwarded-For where addresses after
// the first may represent forwarding proxies earlier in the chain.
@@ -76,17 +78,15 @@ func getIP(r *http.Request) string {
s = len(fwd)
}
addr = fwd[:s]
- } else if fwd := r.Header.Get(xRealIP); fwd != "" {
- // X-Real-IP should only contain one IP address (the client making the
- // request).
- addr = fwd
- } else if fwd := r.Header.Get(forwarded); fwd != "" {
+ case r.Header.Get(xRealIP) != "":
+ addr = r.Header.Get(xRealIP)
+ case r.Header.Get(forwarded) != "":
// match should contain at least two elements if the protocol was
// specified in the Forwarded header. The first element will always be
// the 'for=' capture, which we ignore. In the case of multiple IP
// addresses (for=8.8.8.8, 8.8.4.4,172.16.1.20 is valid) we only
// extract the first, which should be the client IP.
- if match := forRegex.FindStringSubmatch(fwd); len(match) > 1 {
+ if match := forRegex.FindStringSubmatch(r.Header.Get(forwarded)); len(match) > 1 {
// IPv6 addresses in Forwarded headers are quoted-strings. We strip
// these quotes.
addr = strings.Trim(match[1], `"`)