From a05eb66c998c1db2432ce34f1741f03d10dc919d Mon Sep 17 00:00:00 2001 From: Earl Warren Date: Sat, 25 May 2024 23:49:20 +0200 Subject: [PATCH] tests(web): verify compressed files are not re-compressed the test file used has a size below the default threshold and will never be compressed because of that, regardless of its extension. Reduce the threshold to 10 bytes otherwise the test is a false positive. --- routers/web/web.go | 4 +++- tests/integration/repo_archive_test.go | 2 ++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/routers/web/web.go b/routers/web/web.go index 0ab25fd7e3..a65994c246 100644 --- a/routers/web/web.go +++ b/routers/web/web.go @@ -57,6 +57,8 @@ import ( "github.com/prometheus/client_golang/prometheus" ) +var GzipMinSize = gzhttp.DefaultMinSize + // optionsCorsHandler return a http handler which sets CORS options if enabled by config, it blocks non-CORS OPTIONS requests. func optionsCorsHandler() func(next http.Handler) http.Handler { var corsHandler func(next http.Handler) http.Handler @@ -242,7 +244,7 @@ func Routes() *web.Route { var mid []any if setting.EnableGzip { - wrapper, err := gzhttp.NewWrapper(gzhttp.RandomJitter(32, 0, false)) + wrapper, err := gzhttp.NewWrapper(gzhttp.RandomJitter(32, 0, false), gzhttp.MinSize(GzipMinSize)) if err != nil { log.Fatal("gzhttp.NewWrapper failed: %v", err) } diff --git a/tests/integration/repo_archive_test.go b/tests/integration/repo_archive_test.go index ebc6467378..664b04baf7 100644 --- a/tests/integration/repo_archive_test.go +++ b/tests/integration/repo_archive_test.go @@ -11,6 +11,7 @@ import ( "code.gitea.io/gitea/modules/setting" "code.gitea.io/gitea/modules/test" "code.gitea.io/gitea/routers" + "code.gitea.io/gitea/routers/web" "code.gitea.io/gitea/tests" "github.com/stretchr/testify/assert" @@ -19,6 +20,7 @@ import ( func TestRepoDownloadArchive(t *testing.T) { defer tests.PrepareTestEnv(t)() defer test.MockVariableValue(&setting.EnableGzip, true)() + defer test.MockVariableValue(&web.GzipMinSize, 10)() defer test.MockVariableValue(&testWebRoutes, routers.NormalRoutes())() req := NewRequest(t, "GET", "/user2/repo1/archive/master.zip")