mirror of
https://github.com/go-gitea/gitea
synced 2025-07-23 02:38:35 +00:00
Fix context usage (#33554)
Some old code use direct type-casting to get context, it causes problems. This PR fixes all legacy problems and use correct `ctx.Value` to get low-level contexts. Fix #33518
This commit is contained in:
@@ -64,7 +64,7 @@ func Contexter() func(next http.Handler) http.Handler {
|
||||
return http.HandlerFunc(func(resp http.ResponseWriter, req *http.Request) {
|
||||
base := context.NewBaseContext(resp, req)
|
||||
ctx := context.NewWebContext(base, rnd, session.GetSession(req))
|
||||
ctx.SetContextValue(context.WebContextKey, ctx)
|
||||
ctx.SetContextValue(context.WebContextKey, ctx) // FIXME: this should be removed because NewWebContext should already set it
|
||||
ctx.Data.MergeFrom(middleware.CommonTemplateContextData())
|
||||
ctx.Data.MergeFrom(reqctx.ContextData{
|
||||
"Title": ctx.Locale.Tr("install.install"),
|
||||
|
@@ -88,7 +88,7 @@ func Routes() *web.Router {
|
||||
// Fortunately, the LFS handlers are able to handle requests without a complete web context
|
||||
common.AddOwnerRepoGitLFSRoutes(r, func(ctx *context.PrivateContext) {
|
||||
webContext := &context.Context{Base: ctx.Base}
|
||||
ctx.SetContextValue(context.WebContextKey, webContext)
|
||||
ctx.SetContextValue(context.WebContextKey, webContext) // FIXME: this is not ideal but no other way at the moment
|
||||
})
|
||||
})
|
||||
|
||||
|
@@ -1637,7 +1637,7 @@ func registerRoutes(m *web.Router) {
|
||||
}
|
||||
|
||||
m.NotFound(func(w http.ResponseWriter, req *http.Request) {
|
||||
ctx := context.GetWebContext(req)
|
||||
ctx := context.GetWebContext(req.Context())
|
||||
defer routing.RecordFuncInfo(ctx, routing.GetFuncInfo(ctx.NotFound, "WebNotFound"))()
|
||||
ctx.NotFound("", nil)
|
||||
})
|
||||
|
Reference in New Issue
Block a user