Merge pull request 'tests(web): verify compressed files are not re-compressed' (#3909) from earl-warren/forgejo:wip-skip-gzip into forgejo

Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/3909
Reviewed-by: Victoria <efertone@noreply.codeberg.org>
This commit is contained in:
Earl Warren 2024-05-26 11:12:05 +00:00
commit f2204d81f1
2 changed files with 5 additions and 1 deletions

View file

@ -57,6 +57,8 @@ import (
"github.com/prometheus/client_golang/prometheus" "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. // 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 { func optionsCorsHandler() func(next http.Handler) http.Handler {
var corsHandler 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 var mid []any
if setting.EnableGzip { 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 { if err != nil {
log.Fatal("gzhttp.NewWrapper failed: %v", err) log.Fatal("gzhttp.NewWrapper failed: %v", err)
} }

View file

@ -11,6 +11,7 @@ import (
"code.gitea.io/gitea/modules/setting" "code.gitea.io/gitea/modules/setting"
"code.gitea.io/gitea/modules/test" "code.gitea.io/gitea/modules/test"
"code.gitea.io/gitea/routers" "code.gitea.io/gitea/routers"
"code.gitea.io/gitea/routers/web"
"code.gitea.io/gitea/tests" "code.gitea.io/gitea/tests"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
@ -19,6 +20,7 @@ import (
func TestRepoDownloadArchive(t *testing.T) { func TestRepoDownloadArchive(t *testing.T) {
defer tests.PrepareTestEnv(t)() defer tests.PrepareTestEnv(t)()
defer test.MockVariableValue(&setting.EnableGzip, true)() defer test.MockVariableValue(&setting.EnableGzip, true)()
defer test.MockVariableValue(&web.GzipMinSize, 10)()
defer test.MockVariableValue(&testWebRoutes, routers.NormalRoutes())() defer test.MockVariableValue(&testWebRoutes, routers.NormalRoutes())()
req := NewRequest(t, "GET", "/user2/repo1/archive/master.zip") req := NewRequest(t, "GET", "/user2/repo1/archive/master.zip")