diff options
author | Andrey Nering <andrey.nering@gmail.com> | 2016-11-26 10:08:31 -0200 |
---|---|---|
committer | Andrey Nering <andrey.nering@gmail.com> | 2016-11-26 10:13:25 -0200 |
commit | 638dd24cec6f2951ecd4550165b858138c4c3f40 (patch) | |
tree | 8b71b0f1f1bbf419fcfa303af9311d18706acd30 /routers/repo/download.go | |
parent | 0a76d260fa16764ab66bf1623b4cd9e9adfdac27 (diff) | |
download | gitea-638dd24cec6f2951ecd4550165b858138c4c3f40.tar.gz gitea-638dd24cec6f2951ecd4550165b858138c4c3f40.zip |
Fix HTTP headers for issue attachment download
- Download filename was wrong for files other than images. Example: It was `download` instead of `file.pdf`
- PDF was downloading instead of showing on browser
Diffstat (limited to 'routers/repo/download.go')
-rw-r--r-- | routers/repo/download.go | 16 |
1 files changed, 9 insertions, 7 deletions
diff --git a/routers/repo/download.go b/routers/repo/download.go index 3adab315d4..aba0971a4a 100644 --- a/routers/repo/download.go +++ b/routers/repo/download.go @@ -5,8 +5,8 @@ package repo import ( + "fmt" "io" - "path" "code.gitea.io/git" @@ -22,14 +22,16 @@ func ServeData(ctx *context.Context, name string, reader io.Reader) error { buf = buf[:n] } - if !base.IsTextFile(buf) { - if !base.IsImageFile(buf) { - ctx.Resp.Header().Set("Content-Disposition", "attachment; filename=\""+path.Base(ctx.Repo.TreePath)+"\"") - ctx.Resp.Header().Set("Content-Transfer-Encoding", "binary") - } - } else if !ctx.QueryBool("render") { + ctx.Resp.Header().Set("Cache-Control", "public,max-age=86400") + + if base.IsTextFile(buf) || ctx.QueryBool("render") { ctx.Resp.Header().Set("Content-Type", "text/plain; charset=utf-8") + } else if base.IsImageFile(buf) || base.IsPDFFile(buf) { + ctx.Resp.Header().Set("Content-Disposition", fmt.Sprintf(`inline; filename="%s"`, name)) + } else { + ctx.Resp.Header().Set("Content-Disposition", fmt.Sprintf(`attachment; filename="%s"`, name)) } + ctx.Resp.Write(buf) _, err := io.Copy(ctx.Resp, reader) return err |