diff --git a/pkg/middleware/middleware.go b/pkg/middleware/middleware.go index 24ab4279997..9c7f51c3fb5 100644 --- a/pkg/middleware/middleware.go +++ b/pkg/middleware/middleware.go @@ -109,10 +109,11 @@ func allowCacheControl(rw web.ResponseWriter) bool { foundPrivate := false foundPublic := false for _, val := range ccHeaderValues { - if val == "private" { + strings.Contains(val, "private") + if strings.Contains(val, "private") { foundPrivate = true } - if val == "public" { + if strings.Contains(val, "public") { foundPublic = true } } diff --git a/pkg/middleware/middleware_test.go b/pkg/middleware/middleware_test.go index 5e274440a47..0331a31b82e 100644 --- a/pkg/middleware/middleware_test.go +++ b/pkg/middleware/middleware_test.go @@ -158,15 +158,15 @@ func TestMiddlewareContext(t *testing.T) { middlewareScenario(t, "middleware should pass cache-control on 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") + sc.resp.Header().Add("Cache-Control", "private, max-age=86400") sc.resp.Header().Add("X-Grafana-Cache", "true") sc.exec() - assert.Equal(t, "private", sc.resp.Header().Get("Cache-Control")) + 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) { sc = sc.fakeReq("GET", "/api/datasources/1/resources/foo") - sc.resp.Header().Add("Cache-Control", "public") + 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"))