4
4
package common
5
5
6
6
import (
7
+ "context"
7
8
"net/http"
8
9
"strings"
9
10
10
11
user_model "code.gitea.io/gitea/models/user"
11
- "code.gitea.io/gitea/modules/reqctx"
12
12
"code.gitea.io/gitea/modules/setting"
13
13
"code.gitea.io/gitea/modules/web/middleware"
14
14
@@ -21,7 +21,7 @@ func BlockExpensive() func(next http.Handler) http.Handler {
21
21
}
22
22
return func (next http.Handler ) http.Handler {
23
23
return http .HandlerFunc (func (w http.ResponseWriter , req * http.Request ) {
24
- ret := determineRequestPriority (reqctx . FromContext ( req .Context () ))
24
+ ret := determineRequestPriority (req .Context ())
25
25
if ! ret .SignedIn {
26
26
if ret .Expensive || ret .LongPolling {
27
27
http .Redirect (w , req , setting .AppSubURL + "/user/login" , http .StatusSeeOther )
@@ -73,14 +73,15 @@ func isRoutePathForLongPolling(routePattern string) bool {
73
73
return routePattern == "/user/events"
74
74
}
75
75
76
- func determineRequestPriority (reqCtx reqctx. RequestContext ) (ret struct {
76
+ func determineRequestPriority (ctx context. Context ) (ret struct {
77
77
SignedIn bool
78
78
Expensive bool
79
79
LongPolling bool
80
80
},
81
81
) {
82
- chiRoutePath := chi .RouteContext (reqCtx ).RoutePattern ()
83
- if _ , ok := reqCtx .GetData ()[middleware .ContextDataKeySignedUser ].(* user_model.User ); ok {
82
+ dataStore := middleware .GetContextData (ctx )
83
+ chiRoutePath := chi .RouteContext (ctx ).RoutePattern ()
84
+ if _ , ok := dataStore [middleware .ContextDataKeySignedUser ].(* user_model.User ); ok {
84
85
ret .SignedIn = true
85
86
} else {
86
87
ret .Expensive = isRoutePathExpensive (chiRoutePath )
0 commit comments