Merge pull request #1479 from micro/host-fix

Auth host fix
This commit is contained in:
ben-toogood 2020-04-03 14:43:35 +01:00 committed by GitHub
commit 34234fc486
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -102,9 +102,10 @@ func (h authHandler) ServeHTTP(w http.ResponseWriter, req *http.Request) {
func namespaceFromRequest(req *http.Request) (string, error) { func namespaceFromRequest(req *http.Request) (string, error) {
// determine the host, e.g. dev.micro.mu:8080 // determine the host, e.g. dev.micro.mu:8080
host := req.URL.Host host := req.URL.Hostname()
if len(host) == 0 { if len(host) == 0 {
host = req.Host // fallback to req.Host
host, _, _ = net.SplitHostPort(req.Host)
} }
// check for an ip address // check for an ip address
@ -112,12 +113,6 @@ func namespaceFromRequest(req *http.Request) (string, error) {
return auth.DefaultNamespace, nil return auth.DefaultNamespace, nil
} }
// split the host to remove the port
host, _, err := net.SplitHostPort(req.Host)
if err != nil {
return "", err
}
// check for dev enviroment // check for dev enviroment
if host == "localhost" || host == "127.0.0.1" { if host == "localhost" || host == "127.0.0.1" {
return auth.DefaultNamespace, nil return auth.DefaultNamespace, nil