21 lines
731 B
Go
Raw Normal View History

2017-12-02 16:03:36 +00:00
package middleware
2017-12-02 18:19:08 +00:00
// // HTTPSRedirect middleware redirects to HTTPS if needed.
// func HTTPSRedirect() aero.Middleware {
2019-06-01 04:55:49 +00:00
// return func(ctx aero.Context, next func()) {
2017-12-02 18:19:08 +00:00
// request := ctx.Request()
// userAgent := request.Header().Get("User-Agent")
// isBrowser := strings.Contains(userAgent, "Mozilla/") || strings.Contains(userAgent, "Chrome/") || strings.Contains(userAgent, "AppleWebKit/")
2017-12-02 16:03:36 +00:00
2017-12-02 18:19:08 +00:00
// if !strings.HasPrefix(request.Protocol(), "HTTP/2") && isBrowser {
// fmt.Println("Redirect to HTTPS")
2019-06-03 06:06:57 +00:00
// ctx.Redirect(http.StatusTemporaryRedirect, "https://" + request.Host() + request.URL().Path)
2019-06-01 04:55:49 +00:00
// ctx.Response().WriteHeader(ctx.Status())
2017-12-02 18:19:08 +00:00
// return
// }
2017-12-02 16:03:36 +00:00
2017-12-02 18:19:08 +00:00
// // Handle the request
// next()
// }
// }