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>
This commit is contained in:
Patrick O'Doherty 2024-03-27 11:44:17 -07:00 committed by GitHub
parent 3e6306a782
commit b60c4664c7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 3 additions and 3 deletions

View File

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