mirror of
https://github.com/grafana/grafana.git
synced 2024-11-26 02:40:26 -06:00
4ff613a432
Use v0.19.0 of SDK. Support handling of streaming resource response. Disable gzip/compression middleware for resources to allow chunked/streaming response to clients the gzip middleware had to be disabled since it buffers the full response before sending it to the client. Closes #22569 Co-Authored-By: Arve Knudsen <arve.knudsen@gmail.com>
42 lines
926 B
Go
42 lines
926 B
Go
package middleware
|
|
|
|
import (
|
|
"strings"
|
|
|
|
"github.com/go-macaron/gzip"
|
|
"github.com/grafana/grafana/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)
|
|
}
|
|
}
|
|
}
|