Skip to content

Commit b40db99

Browse files
committed
rename variables for clarity
1 parent 9a44396 commit b40db99

File tree

1 file changed

+12
-12
lines changed

1 file changed

+12
-12
lines changed

routers/common/repo.go

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import (
1313
"strings"
1414
"time"
1515

16-
"code.gitea.io/gitea/modules/charset"
16+
charsetModule "code.gitea.io/gitea/modules/charset"
1717
"code.gitea.io/gitea/modules/context"
1818
"code.gitea.io/gitea/modules/git"
1919
"code.gitea.io/gitea/modules/httpcache"
@@ -62,19 +62,19 @@ func ServeData(ctx *context.Context, filePath string, size int64, reader io.Read
6262
}
6363

6464
fileName := path.Base(filePath)
65-
st := typesniffer.DetectContentType(buf)
66-
isPlain := st.IsText() || ctx.FormBool("render")
65+
sniffedType := typesniffer.DetectContentType(buf)
66+
isPlain := sniffedType.IsText() || ctx.FormBool("render")
6767
mimeType := ""
68-
cs := ""
68+
charset := ""
6969

7070
if setting.MimeTypeMap.Enabled {
7171
fileExtension := strings.ToLower(filepath.Ext(fileName))
7272
mimeType = setting.MimeTypeMap.Map[fileExtension]
7373
}
7474

7575
if mimeType == "" {
76-
if st.IsBrowsableBinaryType() {
77-
mimeType = st.GetMimeType()
76+
if sniffedType.IsBrowsableBinaryType() {
77+
mimeType = sniffedType.GetMimeType()
7878
} else if isPlain {
7979
mimeType = "text/plain"
8080
} else {
@@ -83,24 +83,24 @@ func ServeData(ctx *context.Context, filePath string, size int64, reader io.Read
8383
}
8484

8585
if isPlain {
86-
cs, err = charset.DetectEncoding(buf)
86+
charset, err = charsetModule.DetectEncoding(buf)
8787
if err != nil {
8888
log.Error("Detect raw file %s charset failed: %v, using by default utf-8", filePath, err)
89-
cs = "utf-8"
89+
charset = "utf-8"
9090
}
9191
}
9292

93-
if cs != "" {
94-
ctx.Resp.Header().Set("Content-Type", mimeType+"; charset="+strings.ToLower(cs))
93+
if charset != "" {
94+
ctx.Resp.Header().Set("Content-Type", mimeType+"; charset="+strings.ToLower(charset))
9595
} else {
9696
ctx.Resp.Header().Set("Content-Type", mimeType)
9797
}
9898
ctx.Resp.Header().Set("X-Content-Type-Options", "nosniff")
9999

100100
// serve types that can present a security risk with CSP
101-
if st.IsSvgImage() {
101+
if sniffedType.IsSvgImage() {
102102
ctx.Resp.Header().Set("Content-Security-Policy", "default-src 'none'; style-src 'unsafe-inline'; sandbox")
103-
} else if st.IsPDF() {
103+
} else if sniffedType.IsPDF() {
104104
// no sandbox attribute for pdf as it breaks rendering in at least safari. this
105105
// should generally be safe as scripts inside PDF can not escape the PDF document
106106
// see https://bugs.chromium.org/p/chromium/issues/detail?id=413851 for more discussion

0 commit comments

Comments
 (0)