@@ -23,6 +23,7 @@ import (
23
23
"code.gitea.io/gitea/models"
24
24
"code.gitea.io/gitea/modules/auth/sso"
25
25
"code.gitea.io/gitea/modules/base"
26
+ mc "code.gitea.io/gitea/modules/cache"
26
27
"code.gitea.io/gitea/modules/log"
27
28
"code.gitea.io/gitea/modules/middlewares"
28
29
"code.gitea.io/gitea/modules/setting"
@@ -499,23 +500,8 @@ func getCsrfOpts() CsrfOptions {
499
500
500
501
// Contexter initializes a classic context for a request.
501
502
func Contexter () func (next http.Handler ) http.Handler {
502
- rnd := templates .HTMLRenderer ()
503
-
504
- var c cache.Cache
505
- var err error
506
- if setting .CacheService .Enabled {
507
- c , err = cache .NewCacher (cache.Options {
508
- Adapter : setting .CacheService .Adapter ,
509
- AdapterConfig : setting .CacheService .Conn ,
510
- Interval : setting .CacheService .Interval ,
511
- })
512
- if err != nil {
513
- panic (err )
514
- }
515
- }
516
-
503
+ var rnd = templates .HTMLRenderer ()
517
504
var csrfOpts = getCsrfOpts ()
518
- //var flashEncryptionKey, _ = NewSecret()
519
505
520
506
return func (next http.Handler ) http.Handler {
521
507
return http .HandlerFunc (func (resp http.ResponseWriter , req * http.Request ) {
@@ -524,7 +510,7 @@ func Contexter() func(next http.Handler) http.Handler {
524
510
var link = setting .AppSubURL + strings .TrimSuffix (req .URL .EscapedPath (), "/" )
525
511
var ctx = Context {
526
512
Resp : NewResponse (resp ),
527
- Cache : c ,
513
+ Cache : mc . GetCache () ,
528
514
Locale : locale ,
529
515
Link : link ,
530
516
Render : rnd ,
@@ -571,16 +557,14 @@ func Contexter() func(next http.Handler) http.Handler {
571
557
}
572
558
ctx .Resp .Before (func (resp ResponseWriter ) {
573
559
if flash := f .Encode (); len (flash ) > 0 {
574
- if err == nil {
575
- middlewares .SetCookie (resp , "macaron_flash" , flash , 0 ,
576
- setting .SessionConfig .CookiePath ,
577
- middlewares .Domain (setting .SessionConfig .Domain ),
578
- middlewares .HTTPOnly (true ),
579
- middlewares .Secure (setting .SessionConfig .Secure ),
580
- //middlewares.SameSite(opt.SameSite), FIXME: we need a samesite config
581
- )
582
- return
583
- }
560
+ middlewares .SetCookie (resp , "macaron_flash" , flash , 0 ,
561
+ setting .SessionConfig .CookiePath ,
562
+ middlewares .Domain (setting .SessionConfig .Domain ),
563
+ middlewares .HTTPOnly (true ),
564
+ middlewares .Secure (setting .SessionConfig .Secure ),
565
+ //middlewares.SameSite(opt.SameSite), FIXME: we need a samesite config
566
+ )
567
+ return
584
568
}
585
569
586
570
ctx .SetCookie ("macaron_flash" , "" , - 1 ,
0 commit comments