aboutsummaryrefslogtreecommitdiffstats
path: root/routers
diff options
context:
space:
mode:
authorAndrey Nering <andrey.nering@gmail.com>2016-11-27 08:48:26 -0200
committerGitHub <noreply@github.com>2016-11-27 08:48:26 -0200
commitc664ffd1db21c0376719266d594b4dab1df8dee1 (patch)
tree0b2cc88b8ac0c7ec9acbf52d879849730801868a /routers
parent94da47271701401b6959bfd308d6c74fd30b22e2 (diff)
parentd647d02c2f9816effd50b2eea45aa65fb1b4047c (diff)
downloadgitea-c664ffd1db21c0376719266d594b4dab1df8dee1.tar.gz
gitea-c664ffd1db21c0376719266d594b4dab1df8dee1.zip
Merge pull request #270 from andreynering/gitea/http-headers-download
Fix HTTP headers for issue attachment download
Diffstat (limited to 'routers')
-rw-r--r--routers/repo/download.go20
1 files changed, 13 insertions, 7 deletions
diff --git a/routers/repo/download.go b/routers/repo/download.go
index 3adab315d4..85e9fc64c9 100644
--- a/routers/repo/download.go
+++ b/routers/repo/download.go
@@ -5,8 +5,9 @@
package repo
import (
+ "fmt"
"io"
- "path"
+ "strings"
"code.gitea.io/git"
@@ -22,14 +23,19 @@ 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")
+
+ // Google Chrome dislike commas in filenames, so let's change it to a space
+ name = strings.Replace(name, ",", " ", -1)
+
+ 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