forked from forgejo/forgejo
[GITEA] Use maintained gziphandler
- https://github.com/NYTimes/gziphandler doesn't seems to be maintained anymore and Forgejo already includes https://github.com/klauspost/compress which provides a maintained and faster gzip handler fork. - Enables Jitter to prevent BREACH attacks, as this *seems* to be possible in the context of Forgejo. (cherry picked from commitcc2847241d
) (cherry picked from commit99ba56a876
) Conflicts: go.sum https://codeberg.org/forgejo/forgejo/pulls/1581 (cherry picked from commit711638193d
) (cherry picked from commit9c12a37fde
) (cherry picked from commitd130653454
) (cherry picked from commit45a16f8c3c
) (cherry picked from commita497acb31f
) (cherry picked from commitfe87fd8289
) (cherry picked from commit6ac12e6693
) (cherry picked from commit981ec37e1e
) (cherry picked from commit5d6892ec10
) (cherry picked from commit9df7968f4f
) (cherry picked from commit7d588d1833
) Conflicts: routers/web/web.go https://codeberg.org/forgejo/forgejo/pulls/2075 (cherry picked from commitdefb101281
) (cherry picked from commit5830f204a1
) (cherry picked from commit029f4e9863
) (cherry picked from commit816fe55812
) Conflicts: go.sum https://codeberg.org/forgejo/forgejo/pulls/2249
This commit is contained in:
parent
7110bb6a78
commit
99866d8045
6 changed files with 23 additions and 21 deletions
|
@ -49,17 +49,12 @@ import (
|
|||
_ "code.gitea.io/gitea/modules/session" // to registers all internal adapters
|
||||
|
||||
"gitea.com/go-chi/captcha"
|
||||
"github.com/NYTimes/gziphandler"
|
||||
chi_middleware "github.com/go-chi/chi/v5/middleware"
|
||||
"github.com/go-chi/cors"
|
||||
"github.com/klauspost/compress/gzhttp"
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
)
|
||||
|
||||
const (
|
||||
// GzipMinSize represents min size to compress for the body size of response
|
||||
GzipMinSize = 1400
|
||||
)
|
||||
|
||||
// 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
|
||||
|
@ -245,11 +240,11 @@ func Routes() *web.Route {
|
|||
var mid []any
|
||||
|
||||
if setting.EnableGzip {
|
||||
h, err := gziphandler.GzipHandlerWithOpts(gziphandler.MinSize(GzipMinSize))
|
||||
wrapper, err := gzhttp.NewWrapper(gzhttp.RandomJitter(32, 0, false))
|
||||
if err != nil {
|
||||
log.Fatal("GzipHandlerWithOpts failed: %v", err)
|
||||
log.Fatal("gzhttp.NewWrapper failed: %v", err)
|
||||
}
|
||||
mid = append(mid, h)
|
||||
mid = append(mid, wrapper)
|
||||
}
|
||||
|
||||
if setting.Service.EnableCaptcha {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue