Compress more http content-types.
Also, some minor refactoring
This commit is contained in:
+16
-3
@@ -61,7 +61,7 @@ func loggerInjector(next http.Handler) http.Handler {
|
||||
})
|
||||
}
|
||||
|
||||
func robotsTXT(fs fs.FS) func(next http.Handler) http.Handler {
|
||||
func robotsTXT(fs fs.FS) func(http.Handler) http.Handler {
|
||||
return func(next http.Handler) http.Handler {
|
||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
if strings.HasSuffix(r.URL.Path, "/robots.txt") {
|
||||
@@ -74,7 +74,7 @@ func robotsTXT(fs fs.FS) func(next http.Handler) http.Handler {
|
||||
}
|
||||
}
|
||||
|
||||
func corsHandler() func(h http.Handler) http.Handler {
|
||||
func corsHandler() func(http.Handler) http.Handler {
|
||||
return cors.Handler(cors.Options{
|
||||
AllowedOrigins: []string{"*"},
|
||||
AllowedMethods: []string{
|
||||
@@ -91,7 +91,7 @@ func corsHandler() func(h http.Handler) http.Handler {
|
||||
})
|
||||
}
|
||||
|
||||
func secureMiddleware() func(h http.Handler) http.Handler {
|
||||
func secureMiddleware() func(http.Handler) http.Handler {
|
||||
sec := secure.New(secure.Options{
|
||||
ContentTypeNosniff: true,
|
||||
FrameDeny: true,
|
||||
@@ -102,6 +102,19 @@ func secureMiddleware() func(h http.Handler) http.Handler {
|
||||
return sec.Handler
|
||||
}
|
||||
|
||||
func compressMiddleware() func(http.Handler) http.Handler {
|
||||
return middleware.Compress(
|
||||
5,
|
||||
"application/xml",
|
||||
"application/json",
|
||||
"application/javascript",
|
||||
"text/html",
|
||||
"text/plain",
|
||||
"text/css",
|
||||
"text/javascript",
|
||||
)
|
||||
}
|
||||
|
||||
func clientUniqueIdAdder(next http.Handler) http.Handler {
|
||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
ctx := r.Context()
|
||||
|
||||
Reference in New Issue
Block a user