From 975972d57e4d8e71b5188eeacb81c3df4ae3ba39 Mon Sep 17 00:00:00 2001 From: Harshavardhana Date: Wed, 31 May 2017 09:21:02 -0700 Subject: [PATCH] server: Redirection should use globalMinioPort with host without port. (#4445) Currently redirection doesn't work in following scenarios - server started with port ":80" and TLS is configured client requested insecure request on port "80" gets redirected to port 443 and fails. --- cmd/server-mux.go | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/cmd/server-mux.go b/cmd/server-mux.go index c7ca9f163..4977c9d5a 100644 --- a/cmd/server-mux.go +++ b/cmd/server-mux.go @@ -449,12 +449,20 @@ func (m *ServerMux) ListenAndServe(certFile, keyFile string) (err error) { // All http requests start to be processed by httpHandler httpHandler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { if tlsEnabled && r.TLS == nil { + // It is expected that r.Host might not have port + // for standard ports such as "80" and "443". + host, port, _ := net.SplitHostPort(r.Host) + if port == "" { + host = net.JoinHostPort(r.Host, globalMinioPort) + } else { + host = r.Host + } // TLS is enabled but Request is not TLS configured u := url.URL{ Scheme: httpsScheme, Opaque: r.URL.Opaque, User: r.URL.User, - Host: r.Host, + Host: host, Path: r.URL.Path, RawQuery: r.URL.RawQuery, Fragment: r.URL.Fragment,