@@ -26,11 +26,11 @@ import (
26
26
"code.gitea.io/gitea/modules/base"
27
27
mc "code.gitea.io/gitea/modules/cache"
28
28
"code.gitea.io/gitea/modules/log"
29
- "code.gitea.io/gitea/modules/middlewares"
30
29
"code.gitea.io/gitea/modules/setting"
31
30
"code.gitea.io/gitea/modules/templates"
32
31
"code.gitea.io/gitea/modules/translation"
33
32
"code.gitea.io/gitea/modules/util"
33
+ "code.gitea.io/gitea/modules/web/middleware"
34
34
35
35
"gitea.com/go-chi/cache"
36
36
"gitea.com/go-chi/session"
@@ -56,7 +56,7 @@ type Context struct {
56
56
translation.Locale
57
57
Cache cache.Cache
58
58
csrf CSRF
59
- Flash * middlewares .Flash
59
+ Flash * middleware .Flash
60
60
Session session.Store
61
61
62
62
Link string // current request URL
@@ -206,7 +206,7 @@ func (ctx *Context) HTMLString(name string, data interface{}) (string, error) {
206
206
// RenderWithErr used for page has form validation but need to prompt error to users.
207
207
func (ctx * Context ) RenderWithErr (msg string , tpl base.TplName , form interface {}) {
208
208
if form != nil {
209
- middlewares .AssignForm (form , ctx .Data )
209
+ middleware .AssignForm (form , ctx .Data )
210
210
}
211
211
ctx .Flash .ErrorMsg = msg
212
212
ctx .Data ["Flash" ] = ctx .Flash
@@ -384,12 +384,12 @@ func (ctx *Context) Redirect(location string, status ...int) {
384
384
385
385
// SetCookie set cookies to web browser
386
386
func (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 ... )
388
388
}
389
389
390
390
// GetCookie returns given cookie value from request header.
391
391
func (ctx * Context ) GetCookie (name string ) string {
392
- return middlewares .GetCookie (ctx .Req , name )
392
+ return middleware .GetCookie (ctx .Req , name )
393
393
}
394
394
395
395
// GetSuperSecureCookie returns given cookie value from request header with secret string.
@@ -496,10 +496,10 @@ func GetContext(req *http.Request) *Context {
496
496
497
497
// SignedUserName returns signed user's name via context
498
498
func SignedUserName (req * http.Request ) string {
499
- if middlewares .IsInternalPath (req ) {
499
+ if middleware .IsInternalPath (req ) {
500
500
return ""
501
501
}
502
- if middlewares .IsAPIPath (req ) {
502
+ if middleware .IsAPIPath (req ) {
503
503
ctx , ok := req .Context ().Value (apiContextKey ).(* APIContext )
504
504
if ok {
505
505
v := ctx .Data ["SignedUserName" ]
@@ -539,7 +539,7 @@ func Contexter() func(next http.Handler) http.Handler {
539
539
540
540
return func (next http.Handler ) http.Handler {
541
541
return http .HandlerFunc (func (resp http.ResponseWriter , req * http.Request ) {
542
- var locale = middlewares .Locale (resp , req )
542
+ var locale = middleware .Locale (resp , req )
543
543
var startTime = time .Now ()
544
544
var link = setting .AppSubURL + strings .TrimSuffix (req .URL .EscapedPath (), "/" )
545
545
var ctx = Context {
@@ -567,7 +567,7 @@ func Contexter() func(next http.Handler) http.Handler {
567
567
flashCookie := ctx .GetCookie ("macaron_flash" )
568
568
vals , _ := url .ParseQuery (flashCookie )
569
569
if len (vals ) > 0 {
570
- f := & middlewares .Flash {
570
+ f := & middleware .Flash {
571
571
DataStore : & ctx ,
572
572
Values : vals ,
573
573
ErrorMsg : vals .Get ("error" ),
@@ -578,7 +578,7 @@ func Contexter() func(next http.Handler) http.Handler {
578
578
ctx .Data ["Flash" ] = f
579
579
}
580
580
581
- f := & middlewares .Flash {
581
+ f := & middleware .Flash {
582
582
DataStore : & ctx ,
583
583
Values : url.Values {},
584
584
ErrorMsg : "" ,
@@ -588,22 +588,22 @@ func Contexter() func(next http.Handler) http.Handler {
588
588
}
589
589
ctx .Resp .Before (func (resp ResponseWriter ) {
590
590
if flash := f .Encode (); len (flash ) > 0 {
591
- middlewares .SetCookie (resp , "macaron_flash" , flash , 0 ,
591
+ middleware .SetCookie (resp , "macaron_flash" , flash , 0 ,
592
592
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 ),
596
596
//middlewares.SameSite(opt.SameSite), FIXME: we need a samesite config
597
597
)
598
598
return
599
599
}
600
600
601
601
ctx .SetCookie ("macaron_flash" , "" , - 1 ,
602
602
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
607
607
)
608
608
})
609
609
0 commit comments