Vendor main dependencies.
This commit is contained in:
parent
49a09ab7dd
commit
dd5e3fba01
2738 changed files with 1045689 additions and 0 deletions
48
vendor/github.com/vulcand/oxy/forward/rewrite.go
generated
vendored
Normal file
48
vendor/github.com/vulcand/oxy/forward/rewrite.go
generated
vendored
Normal file
|
@ -0,0 +1,48 @@
|
|||
package forward
|
||||
|
||||
import (
|
||||
"net"
|
||||
"net/http"
|
||||
"strings"
|
||||
|
||||
"github.com/vulcand/oxy/utils"
|
||||
)
|
||||
|
||||
// Rewriter is responsible for removing hop-by-hop headers and setting forwarding headers
|
||||
type HeaderRewriter struct {
|
||||
TrustForwardHeader bool
|
||||
Hostname string
|
||||
}
|
||||
|
||||
func (rw *HeaderRewriter) Rewrite(req *http.Request) {
|
||||
if clientIP, _, err := net.SplitHostPort(req.RemoteAddr); err == nil {
|
||||
if rw.TrustForwardHeader {
|
||||
if prior, ok := req.Header[XForwardedFor]; ok {
|
||||
clientIP = strings.Join(prior, ", ") + ", " + clientIP
|
||||
}
|
||||
}
|
||||
req.Header.Set(XForwardedFor, clientIP)
|
||||
}
|
||||
|
||||
if xfp := req.Header.Get(XForwardedProto); xfp != "" && rw.TrustForwardHeader {
|
||||
req.Header.Set(XForwardedProto, xfp)
|
||||
} else if req.TLS != nil {
|
||||
req.Header.Set(XForwardedProto, "https")
|
||||
} else {
|
||||
req.Header.Set(XForwardedProto, "http")
|
||||
}
|
||||
|
||||
if xfh := req.Header.Get(XForwardedHost); xfh != "" && rw.TrustForwardHeader {
|
||||
req.Header.Set(XForwardedHost, xfh)
|
||||
} else if req.Host != "" {
|
||||
req.Header.Set(XForwardedHost, req.Host)
|
||||
}
|
||||
|
||||
if rw.Hostname != "" {
|
||||
req.Header.Set(XForwardedServer, rw.Hostname)
|
||||
}
|
||||
|
||||
// Remove hop-by-hop headers to the backend. Especially important is "Connection" because we want a persistent
|
||||
// connection, regardless of what the client sent to us.
|
||||
utils.RemoveHeaders(req.Header, HopHeaders...)
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue