1
0
mirror of https://github.com/kataras/iris.git synced 2025-12-17 09:57:01 +00:00

add iris.Minify middleware and Context.OnCloseErr/OnConnectionCloseErr

This commit is contained in:
Gerasimos (Makis) Maropoulos
2020-08-15 17:21:57 +03:00
parent ab226d925a
commit ef7d365e81
10 changed files with 178 additions and 4 deletions

View File

@@ -244,6 +244,23 @@ var (
ctx.Next()
}
// Minify is a middleware which minifies the responses
// based on the response content type.
// Note that minification might be slower, caching is advised.
// Customize the minifier through `Application.Minifier()`.
Minify = func(ctx Context) {
w := ctx.Application().Minifier().ResponseWriter(ctx.ResponseWriter().Naive(), ctx.Request())
// Note(@kataras):
// We don't use defer w.Close()
// because this response writer holds a sync.WaitGroup under the hoods
// and we MUST be sure that its wg.Wait is called on request cancelation
// and not in the end of handlers chain execution
// (which if running a time-consuming task it will delay its resource release).
ctx.OnCloseErr(w.Close)
ctx.ResponseWriter().SetWriter(w)
ctx.Next()
}
// MatchImagesAssets is a simple regex expression
// that can be passed to the DirOptions.Cache.CompressIgnore field
// in order to skip compression on already-compressed file types