aboutsummaryrefslogtreecommitdiffstats
path: root/modules/web/handler.go
diff options
context:
space:
mode:
authorLunny Xiao <xiaolunwen@gmail.com>2024-04-21 08:53:45 +0800
committerGitHub <noreply@github.com>2024-04-21 00:53:45 +0000
commite865de1e9d65dc09797d165a51c8e705d2a86030 (patch)
treecf5b645c274b5ca91c23ea49f45e15a290260a12 /modules/web/handler.go
parent99d789e8cdccd20779d1d4d05011f0797afbe292 (diff)
downloadgitea-e865de1e9d65dc09797d165a51c8e705d2a86030.tar.gz
gitea-e865de1e9d65dc09797d165a51c8e705d2a86030.zip
Use maintained gziphandler (#30592)
Replace #27894 --------- Co-authored-by: delvh <dev.lh@web.de> Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
Diffstat (limited to 'modules/web/handler.go')
-rw-r--r--modules/web/handler.go20
1 files changed, 13 insertions, 7 deletions
diff --git a/modules/web/handler.go b/modules/web/handler.go
index 26b7428016..1812c664b3 100644
--- a/modules/web/handler.go
+++ b/modules/web/handler.go
@@ -128,6 +128,16 @@ func hasResponseBeenWritten(argsIn []reflect.Value) bool {
return false
}
+func wrapHandlerProvider[T http.Handler](hp func(next http.Handler) T, funcInfo *routing.FuncInfo) func(next http.Handler) http.Handler {
+ return func(next http.Handler) http.Handler {
+ h := hp(next) // this handle could be dynamically generated, so we can't use it for debug info
+ return http.HandlerFunc(func(resp http.ResponseWriter, req *http.Request) {
+ routing.UpdateFuncInfo(req.Context(), funcInfo)
+ h.ServeHTTP(resp, req)
+ })
+ }
+}
+
// toHandlerProvider converts a handler to a handler provider
// A handler provider is a function that takes a "next" http.Handler, it can be used as a middleware
func toHandlerProvider(handler any) func(next http.Handler) http.Handler {
@@ -138,13 +148,9 @@ func toHandlerProvider(handler any) func(next http.Handler) http.Handler {
}
if hp, ok := handler.(func(next http.Handler) http.Handler); ok {
- return func(next http.Handler) http.Handler {
- h := hp(next) // this handle could be dynamically generated, so we can't use it for debug info
- return http.HandlerFunc(func(resp http.ResponseWriter, req *http.Request) {
- routing.UpdateFuncInfo(req.Context(), funcInfo)
- h.ServeHTTP(resp, req)
- })
- }
+ return wrapHandlerProvider(hp, funcInfo)
+ } else if hp, ok := handler.(func(http.Handler) http.HandlerFunc); ok {
+ return wrapHandlerProvider(hp, funcInfo)
}
provider := func(next http.Handler) http.Handler {