aboutsummaryrefslogtreecommitdiffstats
path: root/services/context
diff options
context:
space:
mode:
authorwxiaoguang <wxiaoguang@gmail.com>2024-11-13 16:58:09 +0800
committerGitHub <noreply@github.com>2024-11-13 16:58:09 +0800
commit0aedb03996d7bdce88b1f0086151f8778b10c1a4 (patch)
treea6586b4efd51cb7c392fde331062005f9c3a9b86 /services/context
parent840ad7eefe2b49ab453b9a89b153a264a8c9f8a2 (diff)
downloadgitea-0aedb03996d7bdce88b1f0086151f8778b10c1a4.tar.gz
gitea-0aedb03996d7bdce88b1f0086151f8778b10c1a4.zip
Fix LFS route mock, realm, middleware names (#32488)
1. move "internal-lfs" route mock to "common-lfs" 2. fine tune tests 3. fix "realm" strings, according to RFC: https://datatracker.ietf.org/doc/html/rfc2617: * realm = "realm" "=" realm-value * realm-value = quoted-string 4. clarify some names of the middlewares, rename `ignXxx` to `optXxx` to match `reqXxx`, and rename ambiguous `requireSignIn` to `reqGitSignIn`
Diffstat (limited to 'services/context')
-rw-r--r--services/context/base.go5
-rw-r--r--services/context/context.go3
2 files changed, 8 insertions, 0 deletions
diff --git a/services/context/base.go b/services/context/base.go
index 68619bf067..d627095584 100644
--- a/services/context/base.go
+++ b/services/context/base.go
@@ -30,6 +30,10 @@ type contextValuePair struct {
valueFn func() any
}
+type BaseContextKeyType struct{}
+
+var BaseContextKey BaseContextKeyType
+
type Base struct {
originCtx context.Context
contextValues []contextValuePair
@@ -315,6 +319,7 @@ func NewBaseContext(resp http.ResponseWriter, req *http.Request) (b *Base, close
Data: middleware.GetContextData(req.Context()),
}
b.Req = b.Req.WithContext(b)
+ b.AppendContextValue(BaseContextKey, b)
b.AppendContextValue(translation.ContextKey, b.Locale)
b.AppendContextValue(httplib.RequestContextKey, b.Req)
return b, b.cleanUp
diff --git a/services/context/context.go b/services/context/context.go
index 6c7128ef68..812a8c27ee 100644
--- a/services/context/context.go
+++ b/services/context/context.go
@@ -65,6 +65,9 @@ type Context struct {
type TemplateContext map[string]any
func init() {
+ web.RegisterResponseStatusProvider[*Base](func(req *http.Request) web_types.ResponseStatusProvider {
+ return req.Context().Value(BaseContextKey).(*Base)
+ })
web.RegisterResponseStatusProvider[*Context](func(req *http.Request) web_types.ResponseStatusProvider {
return req.Context().Value(WebContextKey).(*Context)
})