mirror of
https://github.com/grafana/grafana.git
synced 2024-11-29 20:24:18 -06:00
Previews: use ETag header (#51008)
* use etag header for previews * use unix millis rather than tz-dependant string
This commit is contained in:
parent
204e9754da
commit
644503f5e6
@ -227,12 +227,21 @@ func (hs *thumbService) GetImage(c *models.ReqContext) {
|
||||
return
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
if err != nil || res == nil {
|
||||
hs.log.Error("Error when retrieving thumbnail", "dashboardUid", req.UID, "err", err.Error())
|
||||
c.JSON(500, map[string]string{"dashboardUID": req.UID, "error": "unknown"})
|
||||
return
|
||||
}
|
||||
|
||||
currentEtag := fmt.Sprintf("%d", res.Updated.Unix())
|
||||
c.Resp.Header().Set("ETag", currentEtag)
|
||||
|
||||
previousEtag := c.Req.Header.Get("If-None-Match")
|
||||
if previousEtag == currentEtag {
|
||||
c.Resp.WriteHeader(http.StatusNotModified)
|
||||
return
|
||||
}
|
||||
|
||||
c.Resp.Header().Set("Content-Type", res.MimeType)
|
||||
if _, err := c.Resp.Write(res.Image); err != nil {
|
||||
hs.log.Error("Error writing to response", "dashboardUid", req.UID, "err", err)
|
||||
|
Loading…
Reference in New Issue
Block a user