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.
This commit is contained in:
Harshavardhana 2017-05-31 09:21:02 -07:00 committed by GitHub
parent 458f22f37c
commit 975972d57e

View File

@ -449,12 +449,20 @@ func (m *ServerMux) ListenAndServe(certFile, keyFile string) (err error) {
// All http requests start to be processed by httpHandler // All http requests start to be processed by httpHandler
httpHandler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { httpHandler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if tlsEnabled && r.TLS == nil { 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 // TLS is enabled but Request is not TLS configured
u := url.URL{ u := url.URL{
Scheme: httpsScheme, Scheme: httpsScheme,
Opaque: r.URL.Opaque, Opaque: r.URL.Opaque,
User: r.URL.User, User: r.URL.User,
Host: r.Host, Host: host,
Path: r.URL.Path, Path: r.URL.Path,
RawQuery: r.URL.RawQuery, RawQuery: r.URL.RawQuery,
Fragment: r.URL.Fragment, Fragment: r.URL.Fragment,