|
|
@ -12,6 +12,7 @@ import ( |
|
|
|
"strings" |
|
|
|
"strings" |
|
|
|
|
|
|
|
|
|
|
|
"code.gitea.io/gitea/modules/base" |
|
|
|
"code.gitea.io/gitea/modules/base" |
|
|
|
|
|
|
|
"code.gitea.io/gitea/modules/charset" |
|
|
|
"code.gitea.io/gitea/modules/context" |
|
|
|
"code.gitea.io/gitea/modules/context" |
|
|
|
"code.gitea.io/gitea/modules/git" |
|
|
|
"code.gitea.io/gitea/modules/git" |
|
|
|
"code.gitea.io/gitea/modules/lfs" |
|
|
|
"code.gitea.io/gitea/modules/lfs" |
|
|
@ -33,7 +34,12 @@ func ServeData(ctx *context.Context, name string, reader io.Reader) error { |
|
|
|
name = strings.Replace(name, ",", " ", -1) |
|
|
|
name = strings.Replace(name, ",", " ", -1) |
|
|
|
|
|
|
|
|
|
|
|
if base.IsTextFile(buf) || ctx.QueryBool("render") { |
|
|
|
if base.IsTextFile(buf) || ctx.QueryBool("render") { |
|
|
|
ctx.Resp.Header().Set("Content-Type", "text/plain; charset=utf-8") |
|
|
|
cs, err := charset.DetectEncoding(buf) |
|
|
|
|
|
|
|
if err != nil { |
|
|
|
|
|
|
|
log.Error("Detect raw file %s charset failed: %v, using by default utf-8", name, err) |
|
|
|
|
|
|
|
cs = "utf-8" |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
ctx.Resp.Header().Set("Content-Type", "text/plain; charset="+strings.ToLower(cs)) |
|
|
|
} else if base.IsImageFile(buf) || base.IsPDFFile(buf) { |
|
|
|
} else if base.IsImageFile(buf) || base.IsPDFFile(buf) { |
|
|
|
ctx.Resp.Header().Set("Content-Disposition", fmt.Sprintf(`inline; filename="%s"`, name)) |
|
|
|
ctx.Resp.Header().Set("Content-Disposition", fmt.Sprintf(`inline; filename="%s"`, name)) |
|
|
|
} else { |
|
|
|
} else { |
|
|
|