diff --git a/cmd/http/listener.go b/cmd/http/listener.go index 75df1c551..82ad97c6b 100644 --- a/cmd/http/listener.go +++ b/cmd/http/listener.go @@ -94,8 +94,11 @@ func getResourceHost(bufConn *BufConn, maxHeaderBytes, methodLen int) (resource continue } - if strings.HasPrefix(token, "Host: ") { - host = strings.TrimPrefix(strings.TrimSuffix(token, "\r"), "Host: ") + // HTTP headers are case insensitive, so we should simply convert + // each tokens to their lower case form to match 'host' header. + token = strings.ToLower(token) + if strings.HasPrefix(token, "host: ") { + host = strings.TrimPrefix(strings.TrimSuffix(token, "\r"), "host: ") return resource, host, nil } } diff --git a/cmd/http/listener_test.go b/cmd/http/listener_test.go index 42d47d350..d9ded6dbf 100644 --- a/cmd/http/listener_test.go +++ b/cmd/http/listener_test.go @@ -425,9 +425,11 @@ func TestHTTPListenerAccept(t *testing.T) { }{ {[]string{"localhost:0"}, nil, "GET / HTTP/1.0\r\nHost: example.org\r\n\r\n", "200 OK\r\n", "GET / HTTP/1.0\r\n"}, {[]string{nonLoopBackIP + ":0"}, nil, "POST / HTTP/1.0\r\nHost: example.org\r\n\r\n", "200 OK\r\n", "POST / HTTP/1.0\r\n"}, + {[]string{nonLoopBackIP + ":0"}, nil, "HEAD / HTTP/1.0\r\nhost: example.org\r\n\r\n", "200 OK\r\n", "HEAD / HTTP/1.0\r\n"}, {[]string{"127.0.0.1:0", nonLoopBackIP + ":0"}, nil, "CONNECT \r\nHost: www.example.org\r\n\r\n", "200 OK\r\n", "CONNECT \r\n"}, {[]string{"localhost:0"}, tlsConfig, "GET / HTTP/1.0\r\nHost: example.org\r\n\r\n", "200 OK\r\n", "GET / HTTP/1.0\r\n"}, {[]string{nonLoopBackIP + ":0"}, tlsConfig, "POST / HTTP/1.0\r\nHost: example.org\r\n\r\n", "200 OK\r\n", "POST / HTTP/1.0\r\n"}, + {[]string{nonLoopBackIP + ":0"}, tlsConfig, "HEAD / HTTP/1.0\r\nhost: example.org\r\n\r\n", "200 OK\r\n", "HEAD / HTTP/1.0\r\n"}, {[]string{"127.0.0.1:0", nonLoopBackIP + ":0"}, tlsConfig, "CONNECT \r\nHost: www.example.org\r\n\r\n", "200 OK\r\n", "CONNECT \r\n"}, }