From 0aedb03996d7bdce88b1f0086151f8778b10c1a4 Mon Sep 17 00:00:00 2001 From: wxiaoguang Date: Wed, 13 Nov 2024 16:58:09 +0800 Subject: 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` --- services/context/base.go | 5 +++++ services/context/context.go | 3 +++ 2 files changed, 8 insertions(+) (limited to 'services/context') 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) }) -- cgit v1.2.3