fix: process all X-Forwarded-For headers in the request
This commit is contained in:
parent
54c77ecb54
commit
be44385b42
2 changed files with 107 additions and 81 deletions
|
@ -165,6 +165,12 @@ func (x *XForwarded) rewrite(outreq *http.Request) {
|
|||
unsafeHeader(outreq.Header).Set(xForwardedHost, outreq.Host)
|
||||
}
|
||||
|
||||
// Per https://www.rfc-editor.org/rfc/rfc2616#section-4.2, the Forwarded IPs list is in
|
||||
// the same order as the values in the X-Forwarded-For header(s).
|
||||
if xffs := unsafeHeader(outreq.Header).Values(xForwardedFor); len(xffs) > 0 {
|
||||
unsafeHeader(outreq.Header).Set(xForwardedFor, strings.Join(xffs, ", "))
|
||||
}
|
||||
|
||||
if x.hostname != "" {
|
||||
unsafeHeader(outreq.Header).Set(xForwardedServer, x.hostname)
|
||||
}
|
||||
|
@ -198,6 +204,10 @@ func (h unsafeHeader) Get(key string) string {
|
|||
return h[key][0]
|
||||
}
|
||||
|
||||
func (h unsafeHeader) Values(key string) []string {
|
||||
return h[key]
|
||||
}
|
||||
|
||||
func (h unsafeHeader) Del(key string) {
|
||||
delete(h, key)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue