feat(background): add Last-Modified header (#1376)

Reviewed-on: vikunja/api#1376
Co-authored-by: clos <clos@noreply.kolaente.de>
Co-committed-by: clos <clos@noreply.kolaente.de>
This commit is contained in:
clos 2023-01-29 22:07:46 +00:00 committed by konrad
parent 491a142378
commit f660badc3d
1 changed files with 10 additions and 0 deletions

View File

@ -295,6 +295,11 @@ func GetListBackground(c echo.Context) error {
_ = s.Rollback()
return handler.HandleHTTPError(err, c)
}
stat, err := bgFile.File.Stat()
if err != nil {
_ = s.Rollback()
return handler.HandleHTTPError(err, c)
}
// Unsplash requires pingbacks as per their api usage guidelines.
// To do this in a privacy-preserving manner, we do the ping from inside of Vikunja to not expose any user details.
@ -306,6 +311,11 @@ func GetListBackground(c echo.Context) error {
return handler.HandleHTTPError(err, c)
}
// Set Last-Modified header if we have the file stat, so clients can decide whether to use cached files
if stat != nil {
c.Response().Header().Set(echo.HeaderLastModified, stat.ModTime().UTC().Format(http.TimeFormat))
}
// Serve the file
return c.Stream(http.StatusOK, "image/jpg", bgFile.File)
}