ServeRedirectHTTP serves a single HTTP handler on the provided listener that redirects all incoming HTTP requests to the HTTPS address of the provided fully qualified domain name (FQDN). Callers are responsible for closing the listener.
(ln net.Listener, fqdn string)
| 389 | // fully qualified domain name (FQDN). Callers are responsible for closing the |
| 390 | // listener. |
| 391 | func (s *Server) ServeRedirectHTTP(ln net.Listener, fqdn string) error { |
| 392 | return http.Serve(ln, http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { |
| 393 | new := url.URL{ |
| 394 | Scheme: "https", |
| 395 | Host: fqdn, |
| 396 | Path: r.URL.Path, |
| 397 | RawQuery: r.URL.RawQuery, |
| 398 | } |
| 399 | |
| 400 | http.Redirect(w, r, new.String(), http.StatusMovedPermanently) |
| 401 | })) |
| 402 | } |
| 403 | |
| 404 | // Serve starts the server and listens on the provided listener. It will block |
| 405 | // until the server is closed. The caller is responsible for closing the |