diff --git a/pkg/middleware/middleware.go b/pkg/middleware/middleware.go index cefecc50e06..2b32ba7a5fe 100644 --- a/pkg/middleware/middleware.go +++ b/pkg/middleware/middleware.go @@ -33,6 +33,7 @@ func AddDefaultResponseHeaders(cfg *setting.Cfg) web.Handler { t := web.NewTree() t.Add("/api/datasources/uid/:uid/resources/*", nil) t.Add("/api/datasources/:id/resources/*", nil) + t.Add("/api/plugins/:id/resources/*", nil) return func(c *web.Context) { c.Resp.Before(func(w web.ResponseWriter) { // if response has already been written, skip. diff --git a/pkg/middleware/middleware_test.go b/pkg/middleware/middleware_test.go index 0dd9533a729..1510e6caab1 100644 --- a/pkg/middleware/middleware_test.go +++ b/pkg/middleware/middleware_test.go @@ -116,7 +116,7 @@ func TestMiddlewareContext(t *testing.T) { assert.Empty(t, sc.resp.Header().Get("Expires")) }) - middlewareScenario(t, "middleware should pass cache-control on resources with private cache control", func(t *testing.T, sc *scenarioContext) { + middlewareScenario(t, "middleware should pass cache-control on datasource resources with private cache control", func(t *testing.T, sc *scenarioContext) { sc = sc.fakeReq("GET", "/api/datasources/1/resources/foo") sc.resp.Header().Add("Cache-Control", "private, max-age=86400") sc.resp.Header().Add("X-Grafana-Cache", "true") @@ -124,7 +124,7 @@ func TestMiddlewareContext(t *testing.T) { assert.Equal(t, "private, max-age=86400", sc.resp.Header().Get("Cache-Control")) }) - middlewareScenario(t, "middleware should not pass cache-control on resources with public cache control", func(t *testing.T, sc *scenarioContext) { + middlewareScenario(t, "middleware should not pass cache-control on datasource resources with public cache control", func(t *testing.T, sc *scenarioContext) { sc = sc.fakeReq("GET", "/api/datasources/1/resources/foo") sc.resp.Header().Add("Cache-Control", "public, max-age=86400, private") sc.resp.Header().Add("X-Grafana-Cache", "true") @@ -132,6 +132,22 @@ func TestMiddlewareContext(t *testing.T) { assert.Equal(t, noStore, sc.resp.Header().Get("Cache-Control")) }) + middlewareScenario(t, "middleware should pass cache-control on plugins resources with private cache control", func(t *testing.T, sc *scenarioContext) { + sc = sc.fakeReq("GET", "/api/plugins/1/resources/foo") + sc.resp.Header().Add("Cache-Control", "private, max-age=86400") + sc.resp.Header().Add("X-Grafana-Cache", "true") + sc.exec() + assert.Equal(t, "private, max-age=86400", sc.resp.Header().Get("Cache-Control")) + }) + + middlewareScenario(t, "middleware should not pass cache-control on plugins resources with public cache control", func(t *testing.T, sc *scenarioContext) { + sc = sc.fakeReq("GET", "/api/plugins/1/resources/foo") + sc.resp.Header().Add("Cache-Control", "public, max-age=86400, private") + sc.resp.Header().Add("X-Grafana-Cache", "true") + sc.exec() + assert.Equal(t, noStore, sc.resp.Header().Get("Cache-Control")) + }) + middlewareScenario(t, "middleware should not add Cache-Control header for requests to datasource proxy API", func( t *testing.T, sc *scenarioContext) { sc.fakeReq("GET", "/api/datasources/proxy/1/test").exec()