serve http: add Last-Modified headers to files and directories

This means that using `rclone serve http` preserves modification times
when used with the http backend.

Fixes #4201
This commit is contained in:
Nick Craig-Wood
2020-05-05 09:41:08 +01:00
parent ef9e6794c2
commit bdc91eda0f
2 changed files with 29 additions and 0 deletions

View File

@@ -138,6 +138,9 @@ func (s *server) serveDir(w http.ResponseWriter, r *http.Request, dirRemote stri
orderParm := r.URL.Query().Get("order")
directory.ProcessQueryParams(sortParm, orderParm)
// Set the Last-Modified header to the timestamp
w.Header().Set("Last-Modified", dir.ModTime().UTC().Format(http.TimeFormat))
directory.Serve(w, r)
}
@@ -175,6 +178,9 @@ func (s *server) serveFile(w http.ResponseWriter, r *http.Request, remote string
w.Header().Set("Content-Type", mimeType)
}
// Set the Last-Modified header to the timestamp
w.Header().Set("Last-Modified", file.ModTime().UTC().Format(http.TimeFormat))
// If HEAD no need to read the object since we have set the headers
if r.Method == "HEAD" {
return