Disabled old middleware

This commit is contained in:
2017-12-02 19:19:08 +01:00
parent 6ff9ad1594
commit e7f30607b2
2 changed files with 69 additions and 85 deletions

View File

@ -1,27 +1,20 @@
package middleware
import (
"fmt"
"strings"
// // HTTPSRedirect middleware redirects to HTTPS if needed.
// func HTTPSRedirect() aero.Middleware {
// return func(ctx *aero.Context, next func()) {
// request := ctx.Request()
// userAgent := request.Header().Get("User-Agent")
// isBrowser := strings.Contains(userAgent, "Mozilla/") || strings.Contains(userAgent, "Chrome/") || strings.Contains(userAgent, "AppleWebKit/")
"github.com/aerogo/aero"
)
// if !strings.HasPrefix(request.Protocol(), "HTTP/2") && isBrowser {
// fmt.Println("Redirect to HTTPS")
// ctx.Redirect("https://" + request.Host() + request.URL().Path)
// ctx.Response().WriteHeader(ctx.StatusCode)
// return
// }
// HTTPSRedirect middleware redirects to HTTPS if needed.
func HTTPSRedirect() aero.Middleware {
return func(ctx *aero.Context, next func()) {
request := ctx.Request()
userAgent := request.Header().Get("User-Agent")
isBrowser := strings.Contains(userAgent, "Mozilla/") || strings.Contains(userAgent, "Chrome/") || strings.Contains(userAgent, "AppleWebKit/")
if !strings.HasPrefix(request.Protocol(), "HTTP/2") && isBrowser {
fmt.Println("Redirect to HTTPS")
ctx.Redirect("https://" + request.Host() + request.URL().Path)
ctx.Response().WriteHeader(ctx.StatusCode)
return
}
// Handle the request
next()
}
}
// // Handle the request
// next()
// }
// }