mirror of
https://github.com/rancher/norman.git
synced 2025-09-05 01:00:36 +00:00
Merge pull request #360 from ibuildthecloud/master
Sync URL parsing with Steve
This commit is contained in:
@@ -3,7 +3,6 @@ package urlbuilder
|
|||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
"strings"
|
"strings"
|
||||||
@@ -17,7 +16,6 @@ const (
|
|||||||
ForwardedAPIHostHeader = "X-API-Host"
|
ForwardedAPIHostHeader = "X-API-Host"
|
||||||
ForwardedHostHeader = "X-Forwarded-Host"
|
ForwardedHostHeader = "X-Forwarded-Host"
|
||||||
ForwardedProtoHeader = "X-Forwarded-Proto"
|
ForwardedProtoHeader = "X-Forwarded-Proto"
|
||||||
ForwardedPortHeader = "X-Forwarded-Port"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func New(r *http.Request, version types.APIVersion, schemas *types.Schemas) (types.URLBuilder, error) {
|
func New(r *http.Request, version types.APIVersion, schemas *types.Schemas) (types.URLBuilder, error) {
|
||||||
@@ -51,29 +49,11 @@ func GetHost(r *http.Request, scheme string) string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
host = strings.Split(r.Header.Get(ForwardedHostHeader), ",")[0]
|
host = strings.Split(r.Header.Get(ForwardedHostHeader), ",")[0]
|
||||||
if host == "" {
|
if host != "" {
|
||||||
host = r.Host
|
|
||||||
}
|
|
||||||
|
|
||||||
port := r.Header.Get(ForwardedPortHeader)
|
|
||||||
if port == "" {
|
|
||||||
return host
|
return host
|
||||||
}
|
}
|
||||||
|
|
||||||
if port == "80" && scheme == "http" {
|
return r.Host
|
||||||
return host
|
|
||||||
}
|
|
||||||
|
|
||||||
if port == "443" && scheme == "http" {
|
|
||||||
return host
|
|
||||||
}
|
|
||||||
|
|
||||||
hostname, _, err := net.SplitHostPort(host)
|
|
||||||
if err != nil {
|
|
||||||
hostname = host
|
|
||||||
}
|
|
||||||
|
|
||||||
return strings.Join([]string{hostname, port}, ":")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetScheme(r *http.Request) string {
|
func GetScheme(r *http.Request) string {
|
||||||
|
Reference in New Issue
Block a user