From 07f7c60ae05b5e4a028b5691385c990870c601b0 Mon Sep 17 00:00:00 2001 From: Alexander Emelin Date: Thu, 25 Mar 2021 21:36:52 +0300 Subject: [PATCH] live: fix writing headers in hijacked connection with gzip enabled (#32310) --- pkg/middleware/gziper.go | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/pkg/middleware/gziper.go b/pkg/middleware/gziper.go index bc05273bccd..0b3772ef7c3 100644 --- a/pkg/middleware/gziper.go +++ b/pkg/middleware/gziper.go @@ -10,23 +10,24 @@ import ( const resourcesPath = "/resources" +var gzipIgnoredPathPrefixes = []string{ + "/api/datasources/proxy", // Ignore datasource proxy requests. + "/api/plugin-proxy/", + "/metrics", + "/live/ws", // WebSocket does not support gzip compression. +} + func Gziper() macaron.Handler { gziperLogger := log.New("gziper") gziper := gzip.Gziper() return func(ctx *macaron.Context) { requestPath := ctx.Req.URL.RequestURI() - // ignore datasource proxy requests - if strings.HasPrefix(requestPath, "/api/datasources/proxy") { - return - } - if strings.HasPrefix(requestPath, "/api/plugin-proxy/") { - return - } - - if strings.HasPrefix(requestPath, "/metrics") { - return + for _, pathPrefix := range gzipIgnoredPathPrefixes { + if strings.HasPrefix(requestPath, pathPrefix) { + return + } } // ignore resources