diff options
author | Lunny Xiao <xiaolunwen@gmail.com> | 2021-01-30 16:55:53 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-01-30 10:55:53 +0200 |
commit | 5e20fd6dbf52ede60ed9ac7944db0d3f6769cf86 (patch) | |
tree | 519259f05f7e7fc4dd1df4da521e000ce469567b /modules/context | |
parent | 0e0424c8ecaf6fa3cdd1fcfc154f188014c63dd8 (diff) | |
download | gitea-5e20fd6dbf52ede60ed9ac7944db0d3f6769cf86.tar.gz gitea-5e20fd6dbf52ede60ed9ac7944db0d3f6769cf86.zip |
Move middlewares to web/middleware (#14480)
Co-authored-by: 6543 <6543@obermui.de>
Diffstat (limited to 'modules/context')
-rw-r--r-- | modules/context/api.go | 4 | ||||
-rw-r--r-- | modules/context/context.go | 36 |
2 files changed, 20 insertions, 20 deletions
diff --git a/modules/context/api.go b/modules/context/api.go index aab6905fd1..4757c2eeb4 100644 --- a/modules/context/api.go +++ b/modules/context/api.go @@ -17,8 +17,8 @@ import ( "code.gitea.io/gitea/modules/auth/sso" "code.gitea.io/gitea/modules/git" "code.gitea.io/gitea/modules/log" - "code.gitea.io/gitea/modules/middlewares" "code.gitea.io/gitea/modules/setting" + "code.gitea.io/gitea/modules/web/middleware" "gitea.com/go-chi/session" ) @@ -224,7 +224,7 @@ func APIContexter() func(http.Handler) http.Handler { return func(next http.Handler) http.Handler { return http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) { - var locale = middlewares.Locale(w, req) + var locale = middleware.Locale(w, req) var ctx = APIContext{ Context: &Context{ Resp: NewResponse(w), diff --git a/modules/context/context.go b/modules/context/context.go index 4fd0861df0..bc48c1415d 100644 --- a/modules/context/context.go +++ b/modules/context/context.go @@ -26,11 +26,11 @@ import ( "code.gitea.io/gitea/modules/base" mc "code.gitea.io/gitea/modules/cache" "code.gitea.io/gitea/modules/log" - "code.gitea.io/gitea/modules/middlewares" "code.gitea.io/gitea/modules/setting" "code.gitea.io/gitea/modules/templates" "code.gitea.io/gitea/modules/translation" "code.gitea.io/gitea/modules/util" + "code.gitea.io/gitea/modules/web/middleware" "gitea.com/go-chi/cache" "gitea.com/go-chi/session" @@ -56,7 +56,7 @@ type Context struct { translation.Locale Cache cache.Cache csrf CSRF - Flash *middlewares.Flash + Flash *middleware.Flash Session session.Store Link string // current request URL @@ -206,7 +206,7 @@ func (ctx *Context) HTMLString(name string, data interface{}) (string, error) { // RenderWithErr used for page has form validation but need to prompt error to users. func (ctx *Context) RenderWithErr(msg string, tpl base.TplName, form interface{}) { if form != nil { - middlewares.AssignForm(form, ctx.Data) + middleware.AssignForm(form, ctx.Data) } ctx.Flash.ErrorMsg = msg ctx.Data["Flash"] = ctx.Flash @@ -384,12 +384,12 @@ func (ctx *Context) Redirect(location string, status ...int) { // SetCookie set cookies to web browser func (ctx *Context) SetCookie(name string, value string, others ...interface{}) { - middlewares.SetCookie(ctx.Resp, name, value, others...) + middleware.SetCookie(ctx.Resp, name, value, others...) } // GetCookie returns given cookie value from request header. func (ctx *Context) GetCookie(name string) string { - return middlewares.GetCookie(ctx.Req, name) + return middleware.GetCookie(ctx.Req, name) } // GetSuperSecureCookie returns given cookie value from request header with secret string. @@ -496,10 +496,10 @@ func GetContext(req *http.Request) *Context { // SignedUserName returns signed user's name via context func SignedUserName(req *http.Request) string { - if middlewares.IsInternalPath(req) { + if middleware.IsInternalPath(req) { return "" } - if middlewares.IsAPIPath(req) { + if middleware.IsAPIPath(req) { ctx, ok := req.Context().Value(apiContextKey).(*APIContext) if ok { v := ctx.Data["SignedUserName"] @@ -539,7 +539,7 @@ func Contexter() func(next http.Handler) http.Handler { return func(next http.Handler) http.Handler { return http.HandlerFunc(func(resp http.ResponseWriter, req *http.Request) { - var locale = middlewares.Locale(resp, req) + var locale = middleware.Locale(resp, req) var startTime = time.Now() var link = setting.AppSubURL + strings.TrimSuffix(req.URL.EscapedPath(), "/") var ctx = Context{ @@ -567,7 +567,7 @@ func Contexter() func(next http.Handler) http.Handler { flashCookie := ctx.GetCookie("macaron_flash") vals, _ := url.ParseQuery(flashCookie) if len(vals) > 0 { - f := &middlewares.Flash{ + f := &middleware.Flash{ DataStore: &ctx, Values: vals, ErrorMsg: vals.Get("error"), @@ -578,7 +578,7 @@ func Contexter() func(next http.Handler) http.Handler { ctx.Data["Flash"] = f } - f := &middlewares.Flash{ + f := &middleware.Flash{ DataStore: &ctx, Values: url.Values{}, ErrorMsg: "", @@ -588,11 +588,11 @@ func Contexter() func(next http.Handler) http.Handler { } ctx.Resp.Before(func(resp ResponseWriter) { if flash := f.Encode(); len(flash) > 0 { - middlewares.SetCookie(resp, "macaron_flash", flash, 0, + middleware.SetCookie(resp, "macaron_flash", flash, 0, setting.SessionConfig.CookiePath, - middlewares.Domain(setting.SessionConfig.Domain), - middlewares.HTTPOnly(true), - middlewares.Secure(setting.SessionConfig.Secure), + middleware.Domain(setting.SessionConfig.Domain), + middleware.HTTPOnly(true), + middleware.Secure(setting.SessionConfig.Secure), //middlewares.SameSite(opt.SameSite), FIXME: we need a samesite config ) return @@ -600,10 +600,10 @@ func Contexter() func(next http.Handler) http.Handler { ctx.SetCookie("macaron_flash", "", -1, setting.SessionConfig.CookiePath, - middlewares.Domain(setting.SessionConfig.Domain), - middlewares.HTTPOnly(true), - middlewares.Secure(setting.SessionConfig.Secure), - //middlewares.SameSite(), FIXME: we need a samesite config + middleware.Domain(setting.SessionConfig.Domain), + middleware.HTTPOnly(true), + middleware.Secure(setting.SessionConfig.Secure), + //middleware.SameSite(), FIXME: we need a samesite config ) }) |