loading up the forgejo repo on tangled to test page performance
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Skip gzip for some well-known compressed file types (#30796)

Co-authored-by: silverwind <me@silverwind.io>
(cherry picked from commit be112c1fc30f87a248b30f48e891d1c8c18e8280)

Conflicts:
routers/web/web.go
trivial conflict because of https://codeberg.org/forgejo/forgejo/pulls/1533

authored by

wxiaoguang
silverwind
and committed by
Earl Warren
4e35e5b8 f0e46642

+39
+8
modules/httplib/serve.go
··· 17 17 "time" 18 18 19 19 charsetModule "code.gitea.io/gitea/modules/charset" 20 + "code.gitea.io/gitea/modules/container" 20 21 "code.gitea.io/gitea/modules/httpcache" 21 22 "code.gitea.io/gitea/modules/log" 22 23 "code.gitea.io/gitea/modules/setting" 23 24 "code.gitea.io/gitea/modules/typesniffer" 24 25 "code.gitea.io/gitea/modules/util" 26 + 27 + "github.com/klauspost/compress/gzhttp" 25 28 ) 26 29 27 30 type ServeHeaderOptions struct { ··· 37 40 // ServeSetHeaders sets necessary content serve headers 38 41 func ServeSetHeaders(w http.ResponseWriter, opts *ServeHeaderOptions) { 39 42 header := w.Header() 43 + 44 + skipCompressionExts := container.SetOf(".gz", ".bz2", ".zip", ".xz", ".zst", ".deb", ".apk", ".jar", ".png", ".jpg", ".webp") 45 + if skipCompressionExts.Contains(strings.ToLower(path.Ext(opts.Filename))) { 46 + w.Header().Add(gzhttp.HeaderNoCompression, "1") 47 + } 40 48 41 49 contentType := typesniffer.ApplicationOctetStream 42 50 if opts.ContentType != "" {
+31
tests/integration/repo_archive_test.go
··· 1 + // Copyright 2024 The Gitea Authors. All rights reserved. 2 + // SPDX-License-Identifier: MIT 3 + 4 + package integration 5 + 6 + import ( 7 + "io" 8 + "net/http" 9 + "testing" 10 + 11 + "code.gitea.io/gitea/modules/setting" 12 + "code.gitea.io/gitea/modules/test" 13 + "code.gitea.io/gitea/routers" 14 + "code.gitea.io/gitea/tests" 15 + 16 + "github.com/stretchr/testify/assert" 17 + ) 18 + 19 + func TestRepoDownloadArchive(t *testing.T) { 20 + defer tests.PrepareTestEnv(t)() 21 + defer test.MockVariableValue(&setting.EnableGzip, true)() 22 + defer test.MockVariableValue(&testWebRoutes, routers.NormalRoutes())() 23 + 24 + req := NewRequest(t, "GET", "/user2/repo1/archive/master.zip") 25 + req.Header.Set("Accept-Encoding", "gzip") 26 + resp := MakeRequest(t, req, http.StatusOK) 27 + bs, err := io.ReadAll(resp.Body) 28 + assert.NoError(t, err) 29 + assert.Empty(t, resp.Header().Get("Content-Encoding")) 30 + assert.Equal(t, 320, len(bs)) 31 + }