diff options
author | wxiaoguang <wxiaoguang@gmail.com> | 2024-05-08 21:34:43 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-05-08 13:34:43 +0000 |
commit | d4c2db39bf239d071c6ac96815efa8fd8b03ad94 (patch) | |
tree | 158b7a40af6d1637d57cdde078d94bf1d7c95404 /routers/common | |
parent | d410e2acce22e5b3518a9bf64a9152b32a91fe18 (diff) | |
download | gitea-d4c2db39bf239d071c6ac96815efa8fd8b03ad94.tar.gz gitea-d4c2db39bf239d071c6ac96815efa8fd8b03ad94.zip |
Refactor AppURL usage (#30885) (#30891)
Backport #30885
Fix #30883
Fix #29591
Co-authored-by: KN4CK3R <admin@oldschoolhack.me>
Diffstat (limited to 'routers/common')
-rw-r--r-- | routers/common/middleware.go | 3 | ||||
-rw-r--r-- | routers/common/redirect.go | 2 |
2 files changed, 4 insertions, 1 deletions
diff --git a/routers/common/middleware.go b/routers/common/middleware.go index c7c75fb099..8b661993bb 100644 --- a/routers/common/middleware.go +++ b/routers/common/middleware.go @@ -4,11 +4,13 @@ package common import ( + go_context "context" "fmt" "net/http" "strings" "code.gitea.io/gitea/modules/cache" + "code.gitea.io/gitea/modules/httplib" "code.gitea.io/gitea/modules/process" "code.gitea.io/gitea/modules/setting" "code.gitea.io/gitea/modules/web/middleware" @@ -34,6 +36,7 @@ func ProtocolMiddlewares() (handlers []any) { } }() req = req.WithContext(middleware.WithContextData(req.Context())) + req = req.WithContext(go_context.WithValue(req.Context(), httplib.RequestContextKey, req)) next.ServeHTTP(resp, req) }) }) diff --git a/routers/common/redirect.go b/routers/common/redirect.go index 34044e814b..d64f74ec82 100644 --- a/routers/common/redirect.go +++ b/routers/common/redirect.go @@ -17,7 +17,7 @@ func FetchRedirectDelegate(resp http.ResponseWriter, req *http.Request) { // The typical page is "issue comment" page. The backend responds "/owner/repo/issues/1#comment-2", // then frontend needs this delegate to redirect to the new location with hash correctly. redirect := req.PostFormValue("redirect") - if !httplib.IsCurrentGiteaSiteURL(redirect) { + if !httplib.IsCurrentGiteaSiteURL(req.Context(), redirect) { resp.WriteHeader(http.StatusBadRequest) return } |