Use MarkLongPolling instead of hard-coded route path (#37427)

This commit is contained in:
wxiaoguang
2026-04-26 19:42:29 +08:00
committed by GitHub
parent ebf30ac4db
commit 712b3a54b5
10 changed files with 73 additions and 42 deletions
+5 -4
View File
@@ -23,6 +23,7 @@ import (
"code.gitea.io/gitea/modules/web"
"code.gitea.io/gitea/modules/web/middleware"
"code.gitea.io/gitea/modules/web/routing"
"code.gitea.io/gitea/modules/web/types"
"code.gitea.io/gitea/routers/common"
"code.gitea.io/gitea/routers/web/admin"
"code.gitea.io/gitea/routers/web/auth"
@@ -91,8 +92,8 @@ func optionsCorsHandler() func(next http.Handler) http.Handler {
}
type AuthMiddleware struct {
AllowOAuth2 web.PreMiddlewareProvider
AllowBasic web.PreMiddlewareProvider
AllowOAuth2 types.PreMiddlewareProvider
AllowBasic types.PreMiddlewareProvider
MiddlewareHandler func(*context.Context)
}
@@ -101,7 +102,7 @@ func newWebAuthMiddleware() *AuthMiddleware {
type keyAllowBasic struct{}
webAuth := &AuthMiddleware{}
middlewareSetContextValue := func(key, val any) web.PreMiddlewareProvider {
middlewareSetContextValue := func(key, val any) types.PreMiddlewareProvider {
return func(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
dataStore := reqctx.GetRequestDataStore(r.Context())
@@ -588,7 +589,7 @@ func registerWebRoutes(m *web.Router, webAuth *AuthMiddleware) {
})
}, reqSignOut)
m.Any("/user/events", routing.MarkLongPolling, events.Events)
m.Any("/user/events", routing.MarkLongPolling(), events.Events)
m.Group("/login/oauth", func() {
m.Group("", func() {