Fixes for redirects and uploads with empty host

This commit is contained in:
Remco 2017-03-22 23:39:59 +01:00
parent d6f225e232
commit 2eb2d1d7f4

View file

@ -360,6 +360,7 @@ func getURL(r *http.Request) *url.URL {
if u.Host != "" { if u.Host != "" {
} else if host, port, err := net.SplitHostPort(r.Host); err != nil { } else if host, port, err := net.SplitHostPort(r.Host); err != nil {
u.Host = r.Host
} else { } else {
if port == "80" && u.Scheme == "http" { if port == "80" && u.Scheme == "http" {
u.Host = host u.Host = host
@ -596,7 +597,7 @@ func (s *Server) RedirectHandler(h http.Handler) http.HandlerFunc {
} else if r.Header.Get("X-Forwarded-Proto") == "https" { } else if r.Header.Get("X-Forwarded-Proto") == "https" {
} else if r.URL.Scheme == "https" { } else if r.URL.Scheme == "https" {
} else { } else {
u := *r.URL u := getURL(r)
u.Scheme = "https" u.Scheme = "https"
http.Redirect(w, r, u.String(), http.StatusPermanentRedirect) http.Redirect(w, r, u.String(), http.StatusPermanentRedirect)