Skip to content

Commit ec4ce64

Browse files
committed
one more optimization
1 parent a6b1400 commit ec4ce64

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

routers/common/repo.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ func ServeData(ctx *context.Context, filePath string, size int64, reader io.Read
6363

6464
fileName := path.Base(filePath)
6565
st := typesniffer.DetectContentType(buf)
66+
isPlain := st.IsText() || ctx.FormBool("render")
6667
mimeType := ""
6768
cs := ""
6869

@@ -74,14 +75,14 @@ func ServeData(ctx *context.Context, filePath string, size int64, reader io.Read
7475
if mimeType == "" {
7576
if st.IsBrowsableType() {
7677
mimeType = st.GetContentType()
77-
} else if st.IsText() || ctx.FormBool("render") {
78+
} else if isPlain {
7879
mimeType = "text/plain"
7980
} else {
8081
mimeType = typesniffer.ApplicationOctetStream
8182
}
8283
}
8384

84-
if st.IsText() || ctx.FormBool("render") {
85+
if isPlain {
8586
cs, err = charset.DetectEncoding(buf)
8687
if err != nil {
8788
log.Error("Detect raw file %s charset failed: %v, using by default utf-8", filePath, err)

0 commit comments

Comments
 (0)