@@ -25,13 +25,10 @@ import (
25
25
// sends it to another server, proxying the response back to the
26
26
// client.
27
27
//
28
- // ReverseProxy automatically sets the client IP as the value of the
29
- // X-Forwarded-For header.
30
- // If an X-Forwarded-For header already exists, the client IP is
31
- // appended to the existing values.
32
- // To prevent IP spoofing, be sure to delete any pre-existing
33
- // X-Forwarded-For header coming from the client or
34
- // an untrusted proxy.
28
+ // ReverseProxy automatically sets the X-Forwarded-For,
29
+ // X-Forwarded-Host and X-Forwarded-Proto headers.
30
+ // Previous values of these headers can be preversed by
31
+ // setting TrustForwardedHeaders to true.
35
32
type ReverseProxy struct {
36
33
// Director must be a function which modifies
37
34
// the request into a new request to be sent
@@ -86,11 +83,15 @@ type ReverseProxy struct {
86
83
ErrorHandler func (http.ResponseWriter , * http.Request , error )
87
84
88
85
// TrustForwardedHeaders specifies if X-Forwarded-For,
89
- // X-Forwarded-Proto and X-Forwarded-Host headers comming from
86
+ // X-Forwarded-Proto and X-Forwarded-Host headers coming from
90
87
// the previous proxy must be trusted or not.
88
+ //
91
89
// If true, existing values of X-Forwarded-Proto and
92
90
// X-Forwarded-Host will be preserved, and the current client IP
93
- // will be appended to the list in X-Forwarded-For.
91
+ // will be appended to the list in X-Forwarded-For. In this case
92
+ // be sure that these 3 headers are removed from the request if
93
+ // sent by the client to prevent spoofing attacks.
94
+ //
94
95
// If false, values of these headers will be set regardless of
95
96
// any existing value.
96
97
TrustForwardedHeaders bool
0 commit comments