From fb273881016a51df85cb92358f9a9a24095361d8 Mon Sep 17 00:00:00 2001 From: Harshavardhana Date: Fri, 31 Aug 2018 04:30:32 -0700 Subject: [PATCH] HTTP headers are case insensitive handle them appropriately (#6390) An issue was reproduced when minio-js client functional tests are setting lower case http headers, in our current master branch we specifically look for canonical host header which may be not necessarily true for all http clients. This leads to a perpetual hang on the *net.Conn*. This PR fixes regression caused by #6206 by handling the case insensitivity. --- cmd/http/listener.go | 7 +++++-- cmd/http/listener_test.go | 2 ++ 2 files changed, 7 insertions(+), 2 deletions(-) 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"}, }