aboutsummaryrefslogtreecommitdiff
path: root/routers/repo/download.go
diff options
context:
space:
mode:
authorDon Bowman <don.waterloo@gmail.com>2015-08-12 21:10:00 +0000
committerDon Bowman <don.waterloo@gmail.com>2015-08-12 21:10:00 +0000
commit1cb46ede1acf4f8527e64fcae7e92672cad764b2 (patch)
treefabb54ee5f040be2a4ee5c95f87cb3e9fbf7bdea /routers/repo/download.go
parent9e6bd31d76aa6d6495a2144466af78773f34d07c (diff)
parentaede5cdb04fdbf74d9c602062fdece9f408e90f4 (diff)
Merge branch 'master' of https://github.com/gogits/gogs
Conflicts: routers/repo/download.go
Diffstat (limited to 'routers/repo/download.go')
-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 b1c5fbc8..c71f8d29 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)