aboutsummaryrefslogtreecommitdiffstats
path: root/routers
diff options
context:
space:
mode:
author无闻 <u@gogs.io>2015-07-30 20:22:42 +0800
committer无闻 <u@gogs.io>2015-07-30 20:22:42 +0800
commiteedac7322984ecf8cbfc9fdc7d24a5be75efc6cc (patch)
tree831c6ee0fcb231eed3cb302f30ec7d834bd4d3fc /routers
parent869113704b7f8a8e8f173797d865c813b0e69a4a (diff)
parent2cc050e21ed35d95d824cc22d129fc22ee1318a4 (diff)
downloadgitea-eedac7322984ecf8cbfc9fdc7d24a5be75efc6cc.tar.gz
gitea-eedac7322984ecf8cbfc9fdc7d24a5be75efc6cc.zip
Merge pull request #1404 from wqweto/develop
Allow space and/or percent in file and directory names
Diffstat (limited to 'routers')
-rw-r--r--routers/repo/download.go15
1 files changed, 11 insertions, 4 deletions
diff --git a/routers/repo/download.go b/routers/repo/download.go
index b1c5fbc84d..c71f8d293e 100644
--- a/routers/repo/download.go
+++ b/routers/repo/download.go
@@ -26,10 +26,17 @@ func ServeBlob(ctx *middleware.Context, blob *git.Blob) error {
}
_, isTextFile := base.IsTextFile(buf)
- _, isImageFile := base.IsImageFile(buf)
- if !isTextFile && !isImageFile {
- ctx.Resp.Header().Set("Content-Disposition", "attachment; filename="+path.Base(ctx.Repo.TreeName))
- ctx.Resp.Header().Set("Content-Transfer-Encoding", "binary")
+ if isTextFile {
+ charset, _ := base.DetectEncoding(buf)
+ if charset != "UTF-8" {
+ ctx.Resp.Header().Set("Content-Type", "text/plain; charset="+charset)
+ }
+ } else {
+ _, isImageFile := base.IsImageFile(buf)
+ if !isImageFile {
+ ctx.Resp.Header().Set("Content-Disposition", "attachment; filename="+path.Base(ctx.Repo.TreeName))
+ ctx.Resp.Header().Set("Content-Transfer-Encoding", "binary")
+ }
}
ctx.Resp.Write(buf)
_, err = io.Copy(ctx.Resp, dataRc)