mirror of
https://github.com/grafana/grafana.git
synced 2025-02-16 18:34:52 -06:00
pkg/middleware: Check errors (#19749)
* pkg/middleware: Check errors * pkg/middleware: Log when gzip middleware handler fails
This commit is contained in:
parent
5cf5d89dff
commit
6e7c18fc1c
@ -80,14 +80,15 @@ func TestMiddlewareContext(t *testing.T) {
|
||||
Convey("with a simple cache key", func() {
|
||||
// Set cache key
|
||||
key := fmt.Sprintf(CachePrefix, base32.StdEncoding.EncodeToString([]byte(name)))
|
||||
store.Set(key, int64(33), 0)
|
||||
err := store.Set(key, int64(33), 0)
|
||||
So(err, ShouldBeNil)
|
||||
|
||||
// Set up the middleware
|
||||
auth := prepareMiddleware(t, req, store)
|
||||
id, err := auth.Login()
|
||||
So(err, ShouldBeNil)
|
||||
|
||||
So(auth.getKey(), ShouldEqual, "auth-proxy-sync-ttl:NVQXE23FNRXWO===")
|
||||
So(err, ShouldBeNil)
|
||||
So(id, ShouldEqual, 33)
|
||||
})
|
||||
|
||||
@ -97,14 +98,14 @@ func TestMiddlewareContext(t *testing.T) {
|
||||
req.Header.Add("X-WEBAUTH-GROUPS", group)
|
||||
|
||||
key := fmt.Sprintf(CachePrefix, base32.StdEncoding.EncodeToString([]byte(name+"-"+group)))
|
||||
store.Set(key, int64(33), 0)
|
||||
err := store.Set(key, int64(33), 0)
|
||||
So(err, ShouldBeNil)
|
||||
|
||||
auth := prepareMiddleware(t, req, store)
|
||||
|
||||
id, err := auth.Login()
|
||||
|
||||
So(auth.getKey(), ShouldEqual, "auth-proxy-sync-ttl:NVQXE23FNRXWOLLHOJQWMYLOMEWWG33SMUWXIZLBNU======")
|
||||
So(err, ShouldBeNil)
|
||||
So(auth.getKey(), ShouldEqual, "auth-proxy-sync-ttl:NVQXE23FNRXWOLLHOJQWMYLOMEWWG33SMUWXIZLBNU======")
|
||||
So(id, ShouldEqual, 33)
|
||||
})
|
||||
|
||||
|
@ -346,7 +346,8 @@ func TestMiddlewareContext(t *testing.T) {
|
||||
})
|
||||
|
||||
key := fmt.Sprintf(cachePrefix, base32.StdEncoding.EncodeToString([]byte(name+"-"+group)))
|
||||
sc.remoteCacheService.Set(key, int64(33), 0)
|
||||
err := sc.remoteCacheService.Set(key, int64(33), 0)
|
||||
So(err, ShouldBeNil)
|
||||
sc.fakeReq("GET", "/")
|
||||
|
||||
sc.req.Header.Add(setting.AuthProxyHeaderName, name)
|
||||
|
@ -4,11 +4,13 @@ import (
|
||||
"strings"
|
||||
|
||||
"github.com/go-macaron/gzip"
|
||||
"github.com/grafana/grafana/pkg/infra/log"
|
||||
"gopkg.in/macaron.v1"
|
||||
)
|
||||
|
||||
func Gziper() macaron.Handler {
|
||||
macaronGziper := gzip.Gziper()
|
||||
gziperLogger := log.New("gziper")
|
||||
gziper := gzip.Gziper()
|
||||
|
||||
return func(ctx *macaron.Context) {
|
||||
requestPath := ctx.Req.URL.RequestURI()
|
||||
@ -25,6 +27,8 @@ func Gziper() macaron.Handler {
|
||||
return
|
||||
}
|
||||
|
||||
ctx.Invoke(macaronGziper)
|
||||
if _, err := ctx.Invoke(gziper); err != nil {
|
||||
gziperLogger.Error("Invoking gzip handler failed", "err", err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user