Apply content type exclusion on response

Co-authored-by: kevinpollet <pollet.kevin@gmail.com>
This commit is contained in:
Jean-Baptiste Doumenjou 2021-02-12 12:12:03 +01:00 committed by GitHub
parent 0937cba870
commit 951d61bfcd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 37 additions and 22 deletions

View file

@ -6,8 +6,8 @@ import (
"mime"
"net/http"
"github.com/NYTimes/gziphandler"
"github.com/opentracing/opentracing-go/ext"
"github.com/traefik/gziphandler"
"github.com/traefik/traefik/v2/pkg/config/dynamic"
"github.com/traefik/traefik/v2/pkg/log"
"github.com/traefik/traefik/v2/pkg/middlewares"
@ -52,7 +52,7 @@ func (c *compress) ServeHTTP(rw http.ResponseWriter, req *http.Request) {
c.next.ServeHTTP(rw, req)
} else {
ctx := middlewares.GetLoggerCtx(req.Context(), c.name, typeName)
gzipHandler(ctx, c.next).ServeHTTP(rw, req)
c.gzipHandler(ctx).ServeHTTP(rw, req)
}
}
@ -60,15 +60,16 @@ func (c *compress) GetTracingInformation() (string, ext.SpanKindEnum) {
return c.name, tracing.SpanKindNoneEnum
}
func gzipHandler(ctx context.Context, h http.Handler) http.Handler {
func (c *compress) gzipHandler(ctx context.Context) http.Handler {
wrapper, err := gziphandler.GzipHandlerWithOpts(
gziphandler.ContentTypeExceptions(c.excludes),
gziphandler.CompressionLevel(gzip.DefaultCompression),
gziphandler.MinSize(gziphandler.DefaultMinSize))
if err != nil {
log.FromContext(ctx).Error(err)
}
return wrapper(h)
return wrapper(c.next)
}
func contains(values []string, val string) bool {