/
gziper.go
41 lines (32 loc) · 926 Bytes
/
gziper.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package middleware
import (
"strings"
"github.com/go-macaron/gzip"
"github.com/famarks/grafarg/pkg/infra/log"
"gopkg.in/macaron.v1"
)
const resourcesPath = "/resources"
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
}
// ignore resources
if (strings.HasPrefix(requestPath, "/api/datasources/") || strings.HasPrefix(requestPath, "/api/plugins/")) && strings.Contains(requestPath, resourcesPath) {
return
}
if _, err := ctx.Invoke(gziper); err != nil {
gziperLogger.Error("Invoking gzip handler failed", "err", err)
}
}
}