mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2025-09-19 11:59:24 +08:00
Fix url scheme using for forwarded request with changed proto (#6884)
This commit is contained in:
@@ -719,9 +719,11 @@ func extractHostHeader(r *http.Request) string {
|
||||
|
||||
forwardedHost := r.Header.Get("X-Forwarded-Host")
|
||||
forwardedPort := r.Header.Get("X-Forwarded-Port")
|
||||
forwardedProto := r.Header.Get("X-Forwarded-Proto")
|
||||
|
||||
// If X-Forwarded-Host is set, use that as the host.
|
||||
// If X-Forwarded-Port is set, use that too to form the host.
|
||||
// If X-Forwarded-Proto is set, check if is it default to omit the port.
|
||||
if forwardedHost != "" {
|
||||
extractedHost := forwardedHost
|
||||
host, port, err := net.SplitHostPort(extractedHost)
|
||||
@@ -731,7 +733,11 @@ func extractHostHeader(r *http.Request) string {
|
||||
forwardedPort = port
|
||||
}
|
||||
}
|
||||
if !isDefaultPort(r.URL.Scheme, forwardedPort) {
|
||||
scheme := r.URL.Scheme
|
||||
if forwardedProto != "" {
|
||||
scheme = forwardedProto
|
||||
}
|
||||
if !isDefaultPort(scheme, forwardedPort) {
|
||||
extractedHost = net.JoinHostPort(extractedHost, forwardedPort)
|
||||
}
|
||||
return extractedHost
|
||||
|
Reference in New Issue
Block a user