Skip to content

Commit 2e2d4be

Browse files
committed
fix
1 parent e9b98ae commit 2e2d4be

File tree

7 files changed

+12
-12
lines changed

7 files changed

+12
-12
lines changed

routers/web/web.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1637,7 +1637,7 @@ func registerRoutes(m *web.Router) {
16371637
}
16381638

16391639
m.NotFound(func(w http.ResponseWriter, req *http.Request) {
1640-
ctx := context.GetWebContext(req)
1640+
ctx := context.GetWebContext(req.Context())
16411641
defer routing.RecordFuncInfo(ctx, routing.GetFuncInfo(ctx.NotFound, "WebNotFound"))()
16421642
ctx.NotFound("", nil)
16431643
})

services/auth/auth.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ func handleSignIn(resp http.ResponseWriter, req *http.Request, sess SessionStore
149149
middleware.SetLocaleCookie(resp, user.Language, 0)
150150

151151
// force to generate a new CSRF token
152-
if ctx := gitea_context.GetWebContext(req); ctx != nil {
152+
if ctx := gitea_context.GetWebContext(req.Context()); ctx != nil {
153153
ctx.Csrf.PrepareForSessionUser(ctx)
154154
}
155155
}

services/auth/sspi.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ func (s *SSPI) Verify(req *http.Request, w http.ResponseWriter, store DataStore,
8888
store.GetData()["EnableSSPI"] = true
8989
// in this case, the Verify function is called in Gitea's web context
9090
// FIXME: it doesn't look good to render the page here, why not redirect?
91-
gitea_context.GetWebContext(req).HTML(http.StatusUnauthorized, tplSignIn)
91+
gitea_context.GetWebContext(req.Context()).HTML(http.StatusUnauthorized, tplSignIn)
9292
return nil, err
9393
}
9494
if outToken != "" {

services/context/context.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,9 @@ type webContextKeyType struct{}
7979

8080
var WebContextKey = webContextKeyType{}
8181

82-
func GetWebContext(req *http.Request) *Context {
83-
ctx, _ := req.Context().Value(WebContextKey).(*Context)
84-
return ctx
82+
func GetWebContext(ctx context.Context) *Context {
83+
webCtx, _ := ctx.Value(WebContextKey).(*Context)
84+
return webCtx
8585
}
8686

8787
// ValidateContext is a special context for form validation middleware. It may be different from other contexts.

services/markup/renderhelper.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ func FormalRenderHelperFuncs() *markup.RenderHelperFuncs {
2121
return false
2222
}
2323

24-
giteaCtx, ok := ctx.(*gitea_context.Context)
25-
if !ok {
24+
giteaCtx := gitea_context.GetWebContext(ctx)
25+
if giteaCtx == nil {
2626
// when using general context, use user's visibility to check
2727
return mentionedUser.Visibility.IsPublic()
2828
}

services/markup/renderhelper_codepreview.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ func renderRepoFileCodePreview(ctx context.Context, opts markup.RenderCodePrevie
3636
return "", err
3737
}
3838

39-
webCtx, ok := ctx.Value(gitea_context.WebContextKey).(*gitea_context.Context)
40-
if !ok {
39+
webCtx := gitea_context.GetWebContext(ctx)
40+
if webCtx == nil {
4141
return "", fmt.Errorf("context is not a web context")
4242
}
4343
doer := webCtx.Doer

services/markup/renderhelper_issueicontitle.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ import (
1818
)
1919

2020
func renderRepoIssueIconTitle(ctx context.Context, opts markup.RenderIssueIconTitleOptions) (_ template.HTML, err error) {
21-
webCtx, ok := ctx.Value(gitea_context.WebContextKey).(*gitea_context.Context)
22-
if !ok {
21+
webCtx := gitea_context.GetWebContext(ctx)
22+
if webCtx == nil {
2323
return "", fmt.Errorf("context is not a web context")
2424
}
2525

0 commit comments

Comments
 (0)