Add new handler to redirect to HTTPS if flag is set

Signed-off-by: Josh Michielsen <github@mickey.dev>
This commit is contained in:
Josh Michielsen
2019-10-17 16:30:48 +01:00
parent e24e4ef880
commit aae91b0ad6
2 changed files with 12 additions and 2 deletions
+10
View File
@@ -152,3 +152,13 @@ func (ln tcpKeepAliveListener) Accept() (c net.Conn, err error) {
tc.SetKeepAlivePeriod(3 * time.Minute)
return tc, nil
}
func redirectToHTTPS(opts *Options, h http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if opts.ForceHTTPS {
http.Redirect(w, r, opts.HTTPSAddress, http.StatusPermanentRedirect)
}
h.ServeHTTP(w, r)
})
}