mirror of
https://github.com/grafana/grafana.git
synced 2024-12-23 07:34:08 -06:00
App Plugins: Allow resource handle to define Cache-Control Header (#92559)
This commit is contained in:
parent
4f21ecf982
commit
e2bce38a79
@ -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.
|
||||
|
@ -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()
|
||||
|
Loading…
Reference in New Issue
Block a user