Export: Remove no-store headers in pdf and image previews (#78844)

pull/79640/head
Ezequiel Victorero 1 year ago committed by GitHub
parent 10cc3321cd
commit 864d91ed3e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 1
      pkg/api/render.go
  2. 4
      pkg/middleware/middleware.go
  3. 16
      pkg/middleware/middleware_test.go

@ -89,5 +89,6 @@ func (hs *HTTPServer) RenderToPng(c *contextmodel.ReqContext) {
}
c.Resp.Header().Set("Content-Type", "image/png")
c.Resp.Header().Set("Cache-Control", "private")
http.ServeFile(c.Resp, c.Req, result.FilePath)
}

@ -49,7 +49,9 @@ func AddDefaultResponseHeaders(cfg *setting.Cfg) web.Handler {
resourceCachable := resourceURLMatch && allowCacheControl(c.Resp)
if !strings.HasPrefix(c.Req.URL.Path, "/public/plugins/") &&
!strings.HasPrefix(c.Req.URL.Path, "/avatar/") &&
!strings.HasPrefix(c.Req.URL.Path, "/api/datasources/proxy/") && !resourceCachable {
!strings.HasPrefix(c.Req.URL.Path, "/api/datasources/proxy/") &&
!strings.HasPrefix(c.Req.URL.Path, "/api/reports/render/") &&
!strings.HasPrefix(c.Req.URL.Path, "/render/d-solo/") && !resourceCachable {
addNoCacheHeaders(c.Resp)
}

@ -190,6 +190,22 @@ func TestMiddlewareContext(t *testing.T) {
"X-Other-Header": "other-test",
}
})
middlewareScenario(t, "middleware should not add Cache-Control header for requests to render pdf", func(
t *testing.T, sc *scenarioContext) {
sc.fakeReq("GET", "/api/reports/render/pdf/").exec()
assert.Empty(t, sc.resp.Header().Get("Cache-Control"))
assert.Empty(t, sc.resp.Header().Get("Pragma"))
assert.Empty(t, sc.resp.Header().Get("Expires"))
})
middlewareScenario(t, "middleware should not add Cache-Control header for requests to render panel as image", func(
t *testing.T, sc *scenarioContext) {
sc.fakeReq("GET", "/render/d-solo/").exec()
assert.Empty(t, sc.resp.Header().Get("Cache-Control"))
assert.Empty(t, sc.resp.Header().Get("Pragma"))
assert.Empty(t, sc.resp.Header().Get("Expires"))
})
}
func middlewareScenario(t *testing.T, desc string, fn scenarioFunc, cbs ...func(*setting.Cfg)) {

Loading…
Cancel
Save