util.go 531 B

123456789101112131415161718192021222324252627282930
  1. package middleware
  2. import (
  3. "strings"
  4. "github.com/go-macaron/gzip"
  5. "gopkg.in/macaron.v1"
  6. )
  7. func Gziper() macaron.Handler {
  8. macaronGziper := gzip.Gziper()
  9. return func(ctx *macaron.Context) {
  10. requestPath := ctx.Req.URL.RequestURI()
  11. // ignore datasource proxy requests
  12. if strings.HasPrefix(requestPath, "/api/datasources/proxy") {
  13. return
  14. }
  15. if strings.HasPrefix(requestPath, "/api/plugin-proxy/") {
  16. return
  17. }
  18. if strings.HasPrefix(requestPath, "/metrics") {
  19. return
  20. }
  21. ctx.Invoke(macaronGziper)
  22. }
  23. }