make HTTP->S redirects use same host only for HSTS
1 file changed, 8 insertions(+), 18 deletions(-)
changed files
M internal/server/server.go → internal/server/server.go
@@ -46,10 +46,9 @@ } type Server struct { *http.Server - redirectServer *http.Server - runtimeConfig *Config - config *cfg.Config - log *log.Logger + runtimeConfig *Config + config *cfg.Config + log *log.Logger } func applyDevModeOverrides(config *cfg.Config, runtimeConfig *Config) {@@ -184,15 +183,13 @@ if err != nil { return nil, errors.Wrap(err, "could not create website mux") } - rMux := http.NewServeMux() - rMux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { - path, _ := website.CanonicalisePath(r.URL.Path) - newURL := config.BaseURL.JoinPath(path) - http.Redirect(w, r, newURL.String(), 301) - }) if runtimeConfig.Redirect { loggingMux.Handle(config.BaseURL.Hostname()+"/", mux) - loggingMux.Handle("/", rMux) + loggingMux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { + path, _ := website.CanonicalisePath(r.URL.Path) + newURL := config.BaseURL.JoinPath(path) + http.Redirect(w, r, newURL.String(), http.StatusMovedPermanently) + }) } else { loggingMux.Handle("/", mux) }@@ -214,13 +211,6 @@ ReadTimeout: 1 * time.Minute, WriteTimeout: 2 * time.Minute, IdleTimeout: 10 * time.Minute, Handler: top, - }, - redirectServer: &http.Server{ - ReadHeaderTimeout: 10 * time.Second, - ReadTimeout: 1 * time.Minute, - WriteTimeout: 2 * time.Minute, - IdleTimeout: 10 * time.Minute, - Handler: rMux, }, log: log, config: config,