safeweb: return http.Handler from safeweb.RedirectHTTP (#11538)

Updates #cleanup

Change the return type of the safeweb.RedirectHTTP method to a handler
that can be passed directly to http.Serve without any http.HandlerFunc
wrapping necessary.

Signed-off-by: Patrick O'Doherty <patrick@tailscale.com>
pull/11541/head
Patrick O'Doherty 8 months ago committed by GitHub
parent 3e6306a782
commit b60c4664c7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -199,8 +199,8 @@ func NewServer(config Config) (*Server, error) {
// RedirectHTTP returns a handler that redirects all incoming HTTP requests to // RedirectHTTP returns a handler that redirects all incoming HTTP requests to
// the provided fully qualified domain name (FQDN). // the provided fully qualified domain name (FQDN).
func (s *Server) RedirectHTTP(fqdn string) func(w http.ResponseWriter, r *http.Request) { func (s *Server) RedirectHTTP(fqdn string) http.Handler {
return func(w http.ResponseWriter, r *http.Request) { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
new := url.URL{ new := url.URL{
Scheme: "https", Scheme: "https",
Host: fqdn, Host: fqdn,
@ -209,7 +209,7 @@ func (s *Server) RedirectHTTP(fqdn string) func(w http.ResponseWriter, r *http.R
} }
http.Redirect(w, r, new.String(), http.StatusMovedPermanently) http.Redirect(w, r, new.String(), http.StatusMovedPermanently)
} })
} }
// Serve starts the server and listens on the provided listener. It will block // Serve starts the server and listens on the provided listener. It will block

Loading…
Cancel
Save