| 121 | } |
| 122 | |
| 123 | func parseForwardedHeaders(h http.Header) (forwardedFor, forwardedScheme, forwardedHost string) { |
| 124 | if xForwardedFor := h.Get(headerXForwardedFor); xForwardedFor != "" { |
| 125 | forwardedFor = xForwardedFor |
| 126 | } |
| 127 | if xForwardedProto := h.Get(headerXForwardedProto); xForwardedProto != "" { |
| 128 | forwardedScheme = xForwardedProto |
| 129 | } |
| 130 | if xForwardedHost := h.Get(headerXForwardedHost); xForwardedHost != "" { |
| 131 | forwardedHost = xForwardedHost |
| 132 | } |
| 133 | if forwarded := h.Get(headerForwarded); forwarded != "" { |
| 134 | if match := forwardedForRegex.FindStringSubmatch(forwarded); len(match) > 1 { |
| 135 | forwardedFor = strings.ToLower(match[1]) |
| 136 | } |
| 137 | if match := forwardedProtoRegex.FindStringSubmatch(forwarded); len(match) > 1 { |
| 138 | forwardedScheme = strings.ToLower(match[1]) |
| 139 | } |
| 140 | if match := forwardedHostRegex.FindStringSubmatch(forwarded); len(match) > 1 { |
| 141 | forwardedHost = strings.ToLower(match[1]) |
| 142 | } |
| 143 | } |
| 144 | return forwardedFor, forwardedScheme, forwardedHost |
| 145 | } |