Skip to content

Commit abee597

Browse files
author
zjj
committed
* 'main' of https://github.com/go-gitea/gitea: Add packagist webhook (go-gitea#18224) Fix mime-type detection for HTTP server (go-gitea#18370) Always use git command but not os.Command (go-gitea#18363) Add deprecated for LFS_CONTENT_PATH on zh-cn docs (go-gitea#18362) [skip ci] Updated translations via Crowdin Make gitea, gitea-vet future-proof (go-gitea#18361) Pause queues (go-gitea#15928) Disable content sniffing on `PlainTextBytes` (go-gitea#18359) Update github.com/duo-labs/webauthn (go-gitea#18357)
2 parents d3dbab0 + 3349fd8 commit abee597

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

67 files changed

+1964
-234
lines changed

CONTRIBUTING.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -141,8 +141,8 @@ For imports you should use the following format (_without_ the comments)
141141
```go
142142
import (
143143
// stdlib
144-
"encoding/json"
145144
"fmt"
145+
"math"
146146

147147
// local packages
148148
"code.gitea.io/gitea/models"

docs/content/doc/advanced/config-cheat-sheet.zh-cn.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ menu:
8080

8181
- `LFS_START_SERVER`: 是否启用 git-lfs 支持. 可以为 `true``false`, 默认是 `false`
8282
- `LFS_JWT_SECRET`: LFS 认证密钥,改成自己的。
83-
- `LFS_CONTENT_PATH`: **已废弃**, 存放 lfs 命令上传的文件的地方,默认是 `data/lfs`
83+
- `LFS_CONTENT_PATH`: **已废弃**, 存放 lfs 命令上传的文件的地方,默认是 `data/lfs`**废弃** 请使用 `[lfs]` 的设置。
8484

8585
## Database (`database`)
8686

docs/content/doc/features/webhooks.en-us.md

+1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ All event pushes are POST requests. The methods currently supported are:
2828
- Microsoft Teams
2929
- Feishu
3030
- Wechatwork
31+
- Packagist
3132

3233
### Event information
3334

docs/content/doc/features/webhooks.zh-cn.md

+1
Original file line numberDiff line numberDiff line change
@@ -27,5 +27,6 @@ Gitea 的存储 webhook。这可以有存储库管路设定页 `/:username/:repo
2727
- Microsoft Teams
2828
- Feishu
2929
- Wechatwork
30+
- Packagist
3031

3132
## TBD

docs/content/doc/features/webhooks.zh-tw.md

+1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ Gitea 的儲存庫事件支援 web hook。這可以有儲存庫管理員在設
2727
- Microsoft Teams
2828
- Feishu
2929
- Wechatwork
30+
- Packagist
3031

3132
### 事件資訊
3233

go.mod

+2-4
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ require (
3030
github.com/denisenkom/go-mssqldb v0.10.0
3131
github.com/djherbis/buffer v1.2.0
3232
github.com/djherbis/nio/v3 v3.0.1
33-
github.com/duo-labs/webauthn v0.0.0-20211221191814-a22482edaa3b
33+
github.com/duo-labs/webauthn v0.0.0-20220122034320-81aea484c951
3434
github.com/dustin/go-humanize v1.0.0
3535
github.com/editorconfig/editorconfig-core-go/v2 v2.4.2
3636
github.com/emirpasic/gods v1.12.0
@@ -54,7 +54,7 @@ require (
5454
github.com/golang-jwt/jwt/v4 v4.2.0
5555
github.com/golang/snappy v0.0.4 // indirect
5656
github.com/google/go-github/v39 v39.2.0
57-
github.com/google/uuid v1.2.0
57+
github.com/google/uuid v1.3.0
5858
github.com/gorilla/feeds v1.1.1
5959
github.com/gorilla/mux v1.8.0 // indirect
6060
github.com/gorilla/sessions v1.2.1
@@ -145,8 +145,6 @@ replace github.com/markbates/goth v1.68.0 => github.com/zeripath/goth v1.68.1-0.
145145

146146
replace github.com/shurcooL/vfsgen => github.com/lunny/vfsgen v0.0.0-20220105142115-2c99e1ffdfa0
147147

148-
replace github.com/duo-labs/webauthn => github.com/authelia/webauthn v0.0.0-20211225121951-80d1f2a572e4
149-
150148
replace github.com/satori/go.uuid v1.2.0 => github.com/gofrs/uuid v4.2.0+incompatible
151149

152150
exclude github.com/gofrs/uuid v3.2.0+incompatible

go.sum

+4-5
Original file line numberDiff line numberDiff line change
@@ -131,8 +131,6 @@ github.com/asaskevich/govalidator v0.0.0-20200428143746-21a406dcc535/go.mod h1:o
131131
github.com/asaskevich/govalidator v0.0.0-20200907205600-7a23bdc65eef/go.mod h1:WaHUgvxTVq04UNunO+XhnAqY/wQc+bxr74GqbsZ/Jqw=
132132
github.com/asaskevich/govalidator v0.0.0-20210307081110-f21760c49a8d h1:Byv0BzEl3/e6D5CLfI0j/7hiIEtvGVFPCZ7Ei2oq8iQ=
133133
github.com/asaskevich/govalidator v0.0.0-20210307081110-f21760c49a8d/go.mod h1:WaHUgvxTVq04UNunO+XhnAqY/wQc+bxr74GqbsZ/Jqw=
134-
github.com/authelia/webauthn v0.0.0-20211225121951-80d1f2a572e4 h1:u3eFvgr4A8IjlAokbFt6XY6VdurX7DEYnQMQ4K2yobc=
135-
github.com/authelia/webauthn v0.0.0-20211225121951-80d1f2a572e4/go.mod h1:EYSpSkwoEcryMmQGfhol2IiB3IMN9IIIaNd/wcAQMGQ=
136134
github.com/aws/aws-lambda-go v1.13.3/go.mod h1:4UKl9IzQMoD+QF79YdCuzCwp8VbmG4VAQwij/eHl5CU=
137135
github.com/aws/aws-sdk-go v1.27.0/go.mod h1:KmX6BPdI08NWTb3/sm4ZGu5ShLoqVDhKgpiN924inxo=
138136
github.com/aws/aws-sdk-go v1.34.28/go.mod h1:H7NKnBqNVzoTJpGfLrQkkD+ytBA93eiDYi/+8rV9s48=
@@ -276,6 +274,8 @@ github.com/docker/go-units v0.4.0/go.mod h1:fgPhTUdO+D/Jk86RDLlptpiXQzgHJF7gydDD
276274
github.com/dsnet/compress v0.0.1 h1:PlZu0n3Tuv04TzpfPbrnI0HW/YwodEXDS+oPKahKF0Q=
277275
github.com/dsnet/compress v0.0.1/go.mod h1:Aw8dCMJ7RioblQeTqt88akK31OvO8Dhf5JflhBbQEHo=
278276
github.com/dsnet/golib v0.0.0-20171103203638-1ea166775780/go.mod h1:Lj+Z9rebOhdfkVLjJ8T6VcRQv3SXugXy999NBtR9aFY=
277+
github.com/duo-labs/webauthn v0.0.0-20220122034320-81aea484c951 h1:17esZ09oW+29rklBtCVphIguql2u3NxYH2OasFPPZoo=
278+
github.com/duo-labs/webauthn v0.0.0-20220122034320-81aea484c951/go.mod h1:nHy3JdztZWcsjenDeBuE8gn171OAwg12LBN027UP5AE=
279279
github.com/dustin/go-humanize v0.0.0-20171111073723-bb3d318650d4/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk=
280280
github.com/dustin/go-humanize v1.0.0 h1:VSnTsYCnlFHaM2/igO1h6X3HA71jcobQuxemgkq4zYo=
281281
github.com/dustin/go-humanize v1.0.0/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk=
@@ -491,7 +491,6 @@ github.com/gobwas/glob v0.2.3 h1:A4xDbljILXROh+kObIiy5kIaPYD8e96x1tgBhUI5J+Y=
491491
github.com/gobwas/glob v0.2.3/go.mod h1:d3Ez4x06l9bZtSvzIay5+Yzi0fmZzPgnTbPcKjJAkT8=
492492
github.com/goccy/go-json v0.7.4 h1:B44qRUFwz/vxPKPISQ1KhvzRi9kZ28RAf6YtjriBZ5k=
493493
github.com/goccy/go-json v0.7.4/go.mod h1:6MelG93GURQebXPDq3khkgXZkazVtN9CRI+MGFi0w8I=
494-
github.com/gofrs/uuid v4.2.0+incompatible h1:yyYWMnhkhrKwwr8gAOcOCYxOOscHgDS9yZgBrnJfGa0=
495494
github.com/gofrs/uuid v4.2.0+incompatible/go.mod h1:b2aQJv3Z4Fp6yNu3cdSllBxTCLRxnplIgP/c0N/04lM=
496495
github.com/gogo/googleapis v1.1.0/go.mod h1:gf4bu3Q80BeJ6H1S1vYPm8/ELATdvryBaNFGgqEef3s=
497496
github.com/gogo/protobuf v1.1.1/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ=
@@ -585,8 +584,8 @@ github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm4
585584
github.com/google/uuid v1.0.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
586585
github.com/google/uuid v1.1.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
587586
github.com/google/uuid v1.1.2/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
588-
github.com/google/uuid v1.2.0 h1:qJYtXnJRWmpe7m/3XlyhrsLrEURqHRM2kxzoxXqyUDs=
589-
github.com/google/uuid v1.2.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
587+
github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I=
588+
github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
590589
github.com/googleapis/gax-go/v2 v2.0.4/go.mod h1:0Wqv26UfaUD9n4G6kQubkQ+KchISgw+vpHVxEJEs9eg=
591590
github.com/googleapis/gax-go/v2 v2.0.5/go.mod h1:DWXyrwAJ9X0FpwwEdw+IPEYBICEFu5mhpdKc/us6bOk=
592591
github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY=

models/webhook/webhook.go

+1
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,7 @@ const (
161161
FEISHU HookType = "feishu"
162162
MATRIX HookType = "matrix"
163163
WECHATWORK HookType = "wechatwork"
164+
PACKAGIST HookType = "packagist"
164165
)
165166

166167
// HookStatus is the status of a web hook

modules/context/context.go

+1
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,7 @@ func (ctx *Context) PlainTextBytes(status int, bs []byte) {
292292
}
293293
ctx.Resp.WriteHeader(status)
294294
ctx.Resp.Header().Set("Content-Type", "text/plain;charset=utf-8")
295+
ctx.Resp.Header().Set("X-Content-Type-Options", "nosniff")
295296
if _, err := ctx.Resp.Write(bs); err != nil {
296297
log.Error("Write bytes failed: %v", err)
297298
}

modules/git/diff.go

+14-18
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,11 @@ import (
1111
"fmt"
1212
"io"
1313
"os"
14-
"os/exec"
1514
"regexp"
1615
"strconv"
1716
"strings"
1817

1918
"code.gitea.io/gitea/modules/log"
20-
"code.gitea.io/gitea/modules/process"
2119
)
2220

2321
// RawDiffType type of a raw diff.
@@ -55,43 +53,41 @@ func GetRepoRawDiffForFile(repo *Repository, startCommit, endCommit string, diff
5553
if len(file) > 0 {
5654
fileArgs = append(fileArgs, "--", file)
5755
}
58-
// FIXME: graceful: These commands should have a timeout
59-
ctx, _, finished := process.GetManager().AddContext(repo.Ctx, fmt.Sprintf("GetRawDiffForFile: [repo_path: %s]", repo.Path))
60-
defer finished()
6156

62-
var cmd *exec.Cmd
57+
var args []string
6358
switch diffType {
6459
case RawDiffNormal:
6560
if len(startCommit) != 0 {
66-
cmd = exec.CommandContext(ctx, GitExecutable, append([]string{"diff", "-M", startCommit, endCommit}, fileArgs...)...)
61+
args = append([]string{"diff", "-M", startCommit, endCommit}, fileArgs...)
6762
} else if commit.ParentCount() == 0 {
68-
cmd = exec.CommandContext(ctx, GitExecutable, append([]string{"show", endCommit}, fileArgs...)...)
63+
args = append([]string{"show", endCommit}, fileArgs...)
6964
} else {
7065
c, _ := commit.Parent(0)
71-
cmd = exec.CommandContext(ctx, GitExecutable, append([]string{"diff", "-M", c.ID.String(), endCommit}, fileArgs...)...)
66+
args = append([]string{"diff", "-M", c.ID.String(), endCommit}, fileArgs...)
7267
}
7368
case RawDiffPatch:
7469
if len(startCommit) != 0 {
7570
query := fmt.Sprintf("%s...%s", endCommit, startCommit)
76-
cmd = exec.CommandContext(ctx, GitExecutable, append([]string{"format-patch", "--no-signature", "--stdout", "--root", query}, fileArgs...)...)
71+
args = append([]string{"format-patch", "--no-signature", "--stdout", "--root", query}, fileArgs...)
7772
} else if commit.ParentCount() == 0 {
78-
cmd = exec.CommandContext(ctx, GitExecutable, append([]string{"format-patch", "--no-signature", "--stdout", "--root", endCommit}, fileArgs...)...)
73+
args = append([]string{"format-patch", "--no-signature", "--stdout", "--root", endCommit}, fileArgs...)
7974
} else {
8075
c, _ := commit.Parent(0)
8176
query := fmt.Sprintf("%s...%s", endCommit, c.ID.String())
82-
cmd = exec.CommandContext(ctx, GitExecutable, append([]string{"format-patch", "--no-signature", "--stdout", query}, fileArgs...)...)
77+
args = append([]string{"format-patch", "--no-signature", "--stdout", query}, fileArgs...)
8378
}
8479
default:
8580
return fmt.Errorf("invalid diffType: %s", diffType)
8681
}
8782

8883
stderr := new(bytes.Buffer)
89-
90-
cmd.Dir = repo.Path
91-
cmd.Stdout = writer
92-
cmd.Stderr = stderr
93-
94-
if err = cmd.Run(); err != nil {
84+
cmd := NewCommandContextNoGlobals(repo.Ctx, args...)
85+
if err = cmd.RunWithContext(&RunContext{
86+
Timeout: -1,
87+
Dir: repo.Path,
88+
Stdout: writer,
89+
Stderr: stderr,
90+
}); err != nil {
9591
return fmt.Errorf("Run: %v - %s", err, stderr)
9692
}
9793
return nil

modules/indexer/code/indexer.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -133,11 +133,11 @@ func Init() {
133133
// Create the Queue
134134
switch setting.Indexer.RepoType {
135135
case "bleve", "elasticsearch":
136-
handler := func(data ...queue.Data) {
136+
handler := func(data ...queue.Data) []queue.Data {
137137
idx, err := indexer.get()
138138
if idx == nil || err != nil {
139139
log.Error("Codes indexer handler: unable to get indexer!")
140-
return
140+
return data
141141
}
142142

143143
for _, datum := range data {
@@ -153,6 +153,7 @@ func Init() {
153153
continue
154154
}
155155
}
156+
return nil
156157
}
157158

158159
indexerQueue = queue.CreateUniqueQueue("code_indexer", handler, &IndexerData{})

modules/indexer/issues/indexer.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -103,11 +103,11 @@ func InitIssueIndexer(syncReindex bool) {
103103
// Create the Queue
104104
switch setting.Indexer.IssueType {
105105
case "bleve", "elasticsearch":
106-
handler := func(data ...queue.Data) {
106+
handler := func(data ...queue.Data) []queue.Data {
107107
indexer := holder.get()
108108
if indexer == nil {
109109
log.Error("Issue indexer handler: unable to get indexer!")
110-
return
110+
return data
111111
}
112112

113113
iData := make([]*IndexerData, 0, len(data))
@@ -127,6 +127,7 @@ func InitIssueIndexer(syncReindex bool) {
127127
if err := indexer.Index(iData); err != nil {
128128
log.Error("Error whilst indexing: %v Error: %v", iData, err)
129129
}
130+
return nil
130131
}
131132

132133
issueIndexerQueue = queue.CreateQueue("issue_indexer", handler, &IndexerData{})

modules/indexer/stats/queue.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,14 @@ import (
1717
var statsQueue queue.UniqueQueue
1818

1919
// handle passed PR IDs and test the PRs
20-
func handle(data ...queue.Data) {
20+
func handle(data ...queue.Data) []queue.Data {
2121
for _, datum := range data {
2222
opts := datum.(int64)
2323
if err := indexer.Index(opts); err != nil {
2424
log.Error("stats queue indexer.Index(%d) failed: %v", opts, err)
2525
}
2626
}
27+
return nil
2728
}
2829

2930
func initStatsQueue() error {

modules/json/json.go

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
package json
66

7+
// Allow "encoding/json" import.
78
import (
89
"bytes"
910
"encoding/binary"

modules/notification/ui/ui.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,14 @@ func NewNotifier() base.Notifier {
3838
return ns
3939
}
4040

41-
func (ns *notificationService) handle(data ...queue.Data) {
41+
func (ns *notificationService) handle(data ...queue.Data) []queue.Data {
4242
for _, datum := range data {
4343
opts := datum.(issueNotificationOpts)
4444
if err := models.CreateOrUpdateIssueNotifications(opts.IssueID, opts.CommentID, opts.NotificationAuthorID, opts.ReceiverID); err != nil {
4545
log.Error("Was unable to create issue notification: %v", err)
4646
}
4747
}
48+
return nil
4849
}
4950

5051
func (ns *notificationService) Run() {

modules/public/mime_types.go

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
// Copyright 2022 The Gitea Authors. All rights reserved.
2+
// Use of this source code is governed by a MIT-style
3+
// license that can be found in the LICENSE file.
4+
5+
package public
6+
7+
import "strings"
8+
9+
// wellKnownMimeTypesLower comes from Golang's builtin mime package: `builtinTypesLower`, see the comment of detectWellKnownMimeType
10+
var wellKnownMimeTypesLower = map[string]string{
11+
".avif": "image/avif",
12+
".css": "text/css; charset=utf-8",
13+
".gif": "image/gif",
14+
".htm": "text/html; charset=utf-8",
15+
".html": "text/html; charset=utf-8",
16+
".jpeg": "image/jpeg",
17+
".jpg": "image/jpeg",
18+
".js": "text/javascript; charset=utf-8",
19+
".json": "application/json",
20+
".mjs": "text/javascript; charset=utf-8",
21+
".pdf": "application/pdf",
22+
".png": "image/png",
23+
".svg": "image/svg+xml",
24+
".wasm": "application/wasm",
25+
".webp": "image/webp",
26+
".xml": "text/xml; charset=utf-8",
27+
28+
// well, there are some types missing from the builtin list
29+
".txt": "text/plain; charset=utf-8",
30+
}
31+
32+
// detectWellKnownMimeType will return the mime-type for a well-known file ext name
33+
// The purpose of this function is to bypass the unstable behavior of Golang's mime.TypeByExtension
34+
// mime.TypeByExtension would use OS's mime-type config to overwrite the well-known types (see its document).
35+
// If the user's OS has incorrect mime-type config, it would make Gitea can not respond a correct Content-Type to browsers.
36+
// For example, if Gitea returns `text/plain` for a `.js` file, the browser couldn't run the JS due to security reasons.
37+
// detectWellKnownMimeType makes the Content-Type for well-known files stable.
38+
func detectWellKnownMimeType(ext string) string {
39+
ext = strings.ToLower(ext)
40+
return wellKnownMimeTypesLower[ext]
41+
}

modules/public/public.go

+11
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,15 @@ func parseAcceptEncoding(val string) map[string]bool {
9292
return types
9393
}
9494

95+
// setWellKnownContentType will set the Content-Type if the file is a well-known type.
96+
// See the comments of detectWellKnownMimeType
97+
func setWellKnownContentType(w http.ResponseWriter, file string) {
98+
mimeType := detectWellKnownMimeType(filepath.Ext(file))
99+
if mimeType != "" {
100+
w.Header().Set("Content-Type", mimeType)
101+
}
102+
}
103+
95104
func (opts *Options) handle(w http.ResponseWriter, req *http.Request, fs http.FileSystem, file string) bool {
96105
// use clean to keep the file is a valid path with no . or ..
97106
f, err := fs.Open(path.Clean(file))
@@ -122,6 +131,8 @@ func (opts *Options) handle(w http.ResponseWriter, req *http.Request, fs http.Fi
122131
return true
123132
}
124133

134+
setWellKnownContentType(w, file)
135+
125136
serveContent(w, req, fi, fi.ModTime(), f)
126137
return true
127138
}
File renamed without changes.

modules/public/static.go modules/public/serve_static.go

+9-20
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,12 @@ package public
99

1010
import (
1111
"bytes"
12-
"compress/gzip"
1312
"io"
14-
"mime"
1513
"net/http"
1614
"os"
1715
"path/filepath"
1816
"time"
1917

20-
"code.gitea.io/gitea/modules/log"
2118
"code.gitea.io/gitea/modules/timeutil"
2219
)
2320

@@ -66,24 +63,16 @@ func serveContent(w http.ResponseWriter, req *http.Request, fi os.FileInfo, modt
6663
encodings := parseAcceptEncoding(req.Header.Get("Accept-Encoding"))
6764
if encodings["gzip"] {
6865
if cf, ok := fi.(*vfsgen۰CompressedFileInfo); ok {
69-
rd := bytes.NewReader(cf.GzipBytes())
70-
w.Header().Set("Content-Encoding", "gzip")
71-
ctype := mime.TypeByExtension(filepath.Ext(fi.Name()))
72-
if ctype == "" {
73-
// read a chunk to decide between utf-8 text and binary
74-
var buf [512]byte
75-
grd, _ := gzip.NewReader(rd)
76-
n, _ := io.ReadFull(grd, buf[:])
77-
ctype = http.DetectContentType(buf[:n])
78-
_, err := rd.Seek(0, io.SeekStart) // rewind to output whole file
79-
if err != nil {
80-
log.Error("rd.Seek error: %v", err)
81-
http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
82-
return
83-
}
66+
rdGzip := bytes.NewReader(cf.GzipBytes())
67+
// all static files are managed by Gitea, so we can make sure every file has the correct ext name
68+
// then we can get the correct Content-Type, we do not need to do http.DetectContentType on the decompressed data
69+
mimeType := detectWellKnownMimeType(filepath.Ext(fi.Name()))
70+
if mimeType == "" {
71+
mimeType = "application/octet-stream"
8472
}
85-
w.Header().Set("Content-Type", ctype)
86-
http.ServeContent(w, req, fi.Name(), modtime, rd)
73+
w.Header().Set("Content-Type", mimeType)
74+
w.Header().Set("Content-Encoding", "gzip")
75+
http.ServeContent(w, req, fi.Name(), modtime, rdGzip)
8776
return
8877
}
8978
}

0 commit comments

Comments
 (0)