diff options
author | Frode Aannevik <frode.aa@gmail.com> | 2019-10-20 02:26:56 +0200 |
---|---|---|
committer | Unknwon <u@gogs.io> | 2019-10-19 17:26:56 -0700 |
commit | 1619317c3b3dcc8d01bdd2bd70fcf504eb661516 (patch) | |
tree | d551b47b754041fb21334d5ba54b92bbefb1fdf0 | |
parent | 76fabe87855811c72303f1217b22b0b6310d00a8 (diff) |
repo/download: add Last-Modified response header (#5827)
* repo/download: Add Last-Modified response header
ref: https://github.com/gogs/gogs/issues/5811
* Update download.go
Co-authored-by: Unknwon <u@gogs.io>
-rw-r--r-- | routes/repo/download.go | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/routes/repo/download.go b/routes/repo/download.go index 272669c8..b11baa69 100644 --- a/routes/repo/download.go +++ b/routes/repo/download.go @@ -5,7 +5,9 @@ package repo import ( + "fmt" "io" + "net/http" "path" "github.com/gogs/git-module" @@ -22,6 +24,12 @@ func ServeData(c *context.Context, name string, reader io.Reader) error { buf = buf[:n] } + commit, err := c.Repo.Commit.GetCommitByPath(c.Repo.TreePath) + if err != nil { + return fmt.Errorf("GetCommitByPath: %v", err) + } + c.Resp.Header().Set("Last-Modified", commit.Committer.When.Format(http.TimeFormat)) + if !tool.IsTextFile(buf) { if !tool.IsImageFile(buf) { c.Resp.Header().Set("Content-Disposition", "attachment; filename=\""+name+"\"") @@ -31,7 +39,7 @@ func ServeData(c *context.Context, name string, reader io.Reader) error { c.Resp.Header().Set("Content-Type", "text/plain; charset=utf-8") } c.Resp.Write(buf) - _, err := io.Copy(c.Resp, reader) + _, err = io.Copy(c.Resp, reader) return err } |