diff --git a/httputil/httputil.go b/httputil/httputil.go index f2ba452..8f4c94d 100644 --- a/httputil/httputil.go +++ b/httputil/httputil.go @@ -262,16 +262,12 @@ func ListenAndServe(opts ...Option) error { errs <- server.Serve(ln) }() - if redirectHTTPS { + if redirectHTTPS || config.TLSConfig.GetCertificate != nil { go func() { errs <- (&http.Server{ ReadTimeout: 5 * time.Second, WriteTimeout: 5 * time.Second, - Handler: http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) { - w.Header().Set("Connection", "close") - url := "https://" + req.Host + req.URL.String() - http.Redirect(w, req, url, http.StatusMovedPermanently) - }), + Handler: m.HTTPHandler(http.HandlerFunc(redirect)), }).ListenAndServe() }() } @@ -279,6 +275,12 @@ func ListenAndServe(opts ...Option) error { return <-errs } +func redirect(w http.ResponseWriter, req *http.Request) { + w.Header().Set("Connection", "close") + url := "https://" + req.Host + req.URL.String() + http.Redirect(w, req, url, http.StatusMovedPermanently) +} + // tlsProfile represents a collection of TLS CipherSuites and their compatibility with Web Browsers. // The different profile types are defined on the Mozilla wiki: https://wiki.mozilla.org/Security/Server_Side_TLS type tlsProfile int