2015-04-01 09:00:17 +02:00
|
|
|
package middleware
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"strings"
|
|
|
|
|
|
2016-01-13 15:11:23 +01:00
|
|
|
"github.com/go-macaron/gzip"
|
2019-10-15 18:08:06 +02:00
|
|
|
"github.com/grafana/grafana/pkg/infra/log"
|
2016-01-13 15:38:54 +01:00
|
|
|
"gopkg.in/macaron.v1"
|
2015-04-01 09:00:17 +02:00
|
|
|
)
|
|
|
|
|
|
2020-03-05 19:44:07 +01:00
|
|
|
const resourcesPath = "/resources"
|
|
|
|
|
|
2015-04-01 09:00:17 +02:00
|
|
|
func Gziper() macaron.Handler {
|
2019-10-15 18:08:06 +02:00
|
|
|
gziperLogger := log.New("gziper")
|
|
|
|
|
gziper := gzip.Gziper()
|
2015-04-01 09:00:17 +02:00
|
|
|
|
|
|
|
|
return func(ctx *macaron.Context) {
|
|
|
|
|
requestPath := ctx.Req.URL.RequestURI()
|
2015-04-07 13:48:26 +02:00
|
|
|
// ignore datasource proxy requests
|
2015-04-01 09:00:17 +02:00
|
|
|
if strings.HasPrefix(requestPath, "/api/datasources/proxy") {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
2016-06-02 09:56:53 +02:00
|
|
|
if strings.HasPrefix(requestPath, "/api/plugin-proxy/") {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
2017-10-23 09:35:46 +02:00
|
|
|
if strings.HasPrefix(requestPath, "/metrics") {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
2020-03-05 19:44:07 +01:00
|
|
|
// ignore resources
|
|
|
|
|
if (strings.HasPrefix(requestPath, "/api/datasources/") || strings.HasPrefix(requestPath, "/api/plugins/")) && strings.Contains(requestPath, resourcesPath) {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
2019-10-15 18:08:06 +02:00
|
|
|
if _, err := ctx.Invoke(gziper); err != nil {
|
|
|
|
|
gziperLogger.Error("Invoking gzip handler failed", "err", err)
|
|
|
|
|
}
|
2015-04-01 09:00:17 +02:00
|
|
|
}
|
|
|
|
|
}
|