Skip to content

Commit 0b38ed2

Browse files
committed
Don't unzip files from bindata but send to browser directly
1 parent e0c753e commit 0b38ed2

File tree

10 files changed

+435
-0
lines changed

10 files changed

+435
-0
lines changed

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ require (
8787
github.com/quasoft/websspi v1.0.0
8888
github.com/sergi/go-diff v1.1.0
8989
github.com/shurcooL/httpfs v0.0.0-20190707220628-8d4bc4ba7749 // indirect
90+
github.com/shurcooL/httpgzip v0.0.0-20190720172056-320755c1c1b0
9091
github.com/shurcooL/vfsgen v0.0.0-20200824052919-0d455de96546
9192
github.com/spf13/viper v1.7.1 // indirect
9293
github.com/ssor/bom v0.0.0-20170718123548-6386211fdfcf // indirect

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -986,6 +986,8 @@ github.com/shopspring/decimal v0.0.0-20180709203117-cd690d0c9e24 h1:pntxY8Ary0t4
986986
github.com/shopspring/decimal v0.0.0-20180709203117-cd690d0c9e24/go.mod h1:M+9NzErvs504Cn4c5DxATwIqPbtswREoFCre64PpcG4=
987987
github.com/shurcooL/httpfs v0.0.0-20190707220628-8d4bc4ba7749 h1:bUGsEnyNbVPw06Bs80sCeARAlK8lhwqGyi6UT8ymuGk=
988988
github.com/shurcooL/httpfs v0.0.0-20190707220628-8d4bc4ba7749/go.mod h1:ZY1cvUeJuFPAdZ/B6v7RHavJWZn2YPVFQ1OSXhCGOkg=
989+
github.com/shurcooL/httpgzip v0.0.0-20190720172056-320755c1c1b0 h1:mj/nMDAwTBiaCqMEs4cYCqF7pO6Np7vhy1D1wcQGz+E=
990+
github.com/shurcooL/httpgzip v0.0.0-20190720172056-320755c1c1b0/go.mod h1:919LwcH0M7/W4fcZ0/jy0qGght1GIhqyS/EgWGH2j5Q=
989991
github.com/shurcooL/sanitized_anchor_name v1.0.0 h1:PdmoCO6wvbs+7yrJyMORt4/BmY5IYyJwS/kOiWx8mHo=
990992
github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc=
991993
github.com/shurcooL/vfsgen v0.0.0-20200824052919-0d455de96546 h1:pXY9qYc/MP5zdvqWEUH6SjNiu7VhSjuVFTFiTcphaLU=

modules/public/public.go

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,20 @@
55
package public
66

77
import (
8+
"bytes"
9+
"compress/gzip"
10+
"io"
811
"log"
12+
"mime"
913
"net/http"
1014
"path"
1115
"path/filepath"
1216
"strings"
1317

1418
"code.gitea.io/gitea/modules/httpcache"
1519
"code.gitea.io/gitea/modules/setting"
20+
21+
"github.com/shurcooL/httpgzip"
1622
)
1723

1824
// Options represents the available options to configure the macaron handler.
@@ -157,6 +163,29 @@ func (opts *Options) handle(w http.ResponseWriter, req *http.Request, opt *Optio
157163
return true
158164
}
159165

166+
if _, ok := f.(httpgzip.NotWorthGzipCompressing); !ok {
167+
if g, ok := f.(httpgzip.GzipByter); ok {
168+
w.Header().Set("Content-Encoding", "gzip")
169+
rd := bytes.NewReader(g.GzipBytes())
170+
ctype := mime.TypeByExtension(filepath.Ext(fi.Name()))
171+
if ctype == "" {
172+
// read a chunk to decide between utf-8 text and binary
173+
var buf [512]byte
174+
grd, _ := gzip.NewReader(rd)
175+
n, _ := io.ReadFull(grd, buf[:])
176+
ctype = http.DetectContentType(buf[:n])
177+
_, err := rd.Seek(0, io.SeekStart) // rewind to output whole file
178+
if err != nil {
179+
log.Printf("rd.Seek error: %v\n", err)
180+
return false
181+
}
182+
}
183+
w.Header().Set("Content-Type", ctype)
184+
http.ServeContent(w, req, file, fi.ModTime(), rd)
185+
return true
186+
}
187+
}
188+
160189
http.ServeContent(w, req, file, fi.ModTime(), f)
161190
return true
162191
}

vendor/github.com/shurcooL/httpgzip/.travis.yml

Lines changed: 16 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/shurcooL/httpgzip/LICENSE

Lines changed: 21 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/shurcooL/httpgzip/README.md

Lines changed: 19 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/shurcooL/httpgzip/doc.go

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/shurcooL/httpgzip/fs.go

Lines changed: 226 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)