@@ -26,11 +26,11 @@ import (
2626 "code.gitea.io/gitea/modules/base"
2727 mc "code.gitea.io/gitea/modules/cache"
2828 "code.gitea.io/gitea/modules/log"
29- "code.gitea.io/gitea/modules/middlewares"
3029 "code.gitea.io/gitea/modules/setting"
3130 "code.gitea.io/gitea/modules/templates"
3231 "code.gitea.io/gitea/modules/translation"
3332 "code.gitea.io/gitea/modules/util"
33+ "code.gitea.io/gitea/modules/web/middleware"
3434
3535 "gitea.com/go-chi/cache"
3636 "gitea.com/go-chi/session"
@@ -56,7 +56,7 @@ type Context struct {
5656 translation.Locale
5757 Cache cache.Cache
5858 csrf CSRF
59- Flash * middlewares .Flash
59+ Flash * middleware .Flash
6060 Session session.Store
6161
6262 Link string // current request URL
@@ -206,7 +206,7 @@ func (ctx *Context) HTMLString(name string, data interface{}) (string, error) {
206206// RenderWithErr used for page has form validation but need to prompt error to users.
207207func (ctx * Context ) RenderWithErr (msg string , tpl base.TplName , form interface {}) {
208208 if form != nil {
209- middlewares .AssignForm (form , ctx .Data )
209+ middleware .AssignForm (form , ctx .Data )
210210 }
211211 ctx .Flash .ErrorMsg = msg
212212 ctx .Data ["Flash" ] = ctx .Flash
@@ -384,12 +384,12 @@ func (ctx *Context) Redirect(location string, status ...int) {
384384
385385// SetCookie set cookies to web browser
386386func (ctx * Context ) SetCookie (name string , value string , others ... interface {}) {
387- middlewares .SetCookie (ctx .Resp , name , value , others ... )
387+ middleware .SetCookie (ctx .Resp , name , value , others ... )
388388}
389389
390390// GetCookie returns given cookie value from request header.
391391func (ctx * Context ) GetCookie (name string ) string {
392- return middlewares .GetCookie (ctx .Req , name )
392+ return middleware .GetCookie (ctx .Req , name )
393393}
394394
395395// GetSuperSecureCookie returns given cookie value from request header with secret string.
@@ -496,10 +496,10 @@ func GetContext(req *http.Request) *Context {
496496
497497// SignedUserName returns signed user's name via context
498498func SignedUserName (req * http.Request ) string {
499- if middlewares .IsInternalPath (req ) {
499+ if middleware .IsInternalPath (req ) {
500500 return ""
501501 }
502- if middlewares .IsAPIPath (req ) {
502+ if middleware .IsAPIPath (req ) {
503503 ctx , ok := req .Context ().Value (apiContextKey ).(* APIContext )
504504 if ok {
505505 v := ctx .Data ["SignedUserName" ]
@@ -539,7 +539,7 @@ func Contexter() func(next http.Handler) http.Handler {
539539
540540 return func (next http.Handler ) http.Handler {
541541 return http .HandlerFunc (func (resp http.ResponseWriter , req * http.Request ) {
542- var locale = middlewares .Locale (resp , req )
542+ var locale = middleware .Locale (resp , req )
543543 var startTime = time .Now ()
544544 var link = setting .AppSubURL + strings .TrimSuffix (req .URL .EscapedPath (), "/" )
545545 var ctx = Context {
@@ -567,7 +567,7 @@ func Contexter() func(next http.Handler) http.Handler {
567567 flashCookie := ctx .GetCookie ("macaron_flash" )
568568 vals , _ := url .ParseQuery (flashCookie )
569569 if len (vals ) > 0 {
570- f := & middlewares .Flash {
570+ f := & middleware .Flash {
571571 DataStore : & ctx ,
572572 Values : vals ,
573573 ErrorMsg : vals .Get ("error" ),
@@ -578,7 +578,7 @@ func Contexter() func(next http.Handler) http.Handler {
578578 ctx .Data ["Flash" ] = f
579579 }
580580
581- f := & middlewares .Flash {
581+ f := & middleware .Flash {
582582 DataStore : & ctx ,
583583 Values : url.Values {},
584584 ErrorMsg : "" ,
@@ -588,22 +588,22 @@ func Contexter() func(next http.Handler) http.Handler {
588588 }
589589 ctx .Resp .Before (func (resp ResponseWriter ) {
590590 if flash := f .Encode (); len (flash ) > 0 {
591- middlewares .SetCookie (resp , "macaron_flash" , flash , 0 ,
591+ middleware .SetCookie (resp , "macaron_flash" , flash , 0 ,
592592 setting .SessionConfig .CookiePath ,
593- middlewares .Domain (setting .SessionConfig .Domain ),
594- middlewares .HTTPOnly (true ),
595- middlewares .Secure (setting .SessionConfig .Secure ),
593+ middleware .Domain (setting .SessionConfig .Domain ),
594+ middleware .HTTPOnly (true ),
595+ middleware .Secure (setting .SessionConfig .Secure ),
596596 //middlewares.SameSite(opt.SameSite), FIXME: we need a samesite config
597597 )
598598 return
599599 }
600600
601601 ctx .SetCookie ("macaron_flash" , "" , - 1 ,
602602 setting .SessionConfig .CookiePath ,
603- middlewares .Domain (setting .SessionConfig .Domain ),
604- middlewares .HTTPOnly (true ),
605- middlewares .Secure (setting .SessionConfig .Secure ),
606- //middlewares .SameSite(), FIXME: we need a samesite config
603+ middleware .Domain (setting .SessionConfig .Domain ),
604+ middleware .HTTPOnly (true ),
605+ middleware .Secure (setting .SessionConfig .Secure ),
606+ //middleware .SameSite(), FIXME: we need a samesite config
607607 )
608608 })
609609
0 commit comments