diff --git a/context/timeout.go b/context/timeout.go index f5a816a6f..a38fb593e 100644 --- a/context/timeout.go +++ b/context/timeout.go @@ -36,7 +36,7 @@ func (t *timeoutContext) SetupContext(c configurationtypes.AbstractConfiguration t.timeoutBackend = c.GetDefaultCache().GetTimeout().Backend.Duration } c.GetLogger().Infof("Set backend timeout to %v", t.timeoutBackend) - c.GetLogger().Infof("Set cache timeout to %v", t.timeoutBackend) + c.GetLogger().Infof("Set cache timeout to %v", t.timeoutCache) } func (t *timeoutContext) SetContext(req *http.Request) *http.Request { diff --git a/docs/e2e/Souin E2E.postman_collection.json b/docs/e2e/Souin E2E.postman_collection.json index 9c8aba953..2c118f9ba 100644 --- a/docs/e2e/Souin E2E.postman_collection.json +++ b/docs/e2e/Souin E2E.postman_collection.json @@ -3498,7 +3498,7 @@ " pm.response.to.have.status(200);", " if (exclude) {", " pm.response.to.have.header(\"Cache-Status\");", - " pm.expect(pm.response.headers.get(\"Cache-Status\")).to.eql(\"Souin; fwd=uri-miss; key=; detail=CANNOT-HANDLE\");", + " pm.expect(pm.response.headers.get(\"Cache-Status\")).to.eql(\"Souin; fwd=uri-miss; key=*****; detail=CANNOT-HANDLE\");", " } else {", " pm.response.to.have.header(\"Cache-Status\");", " if (isStore) {", @@ -3516,7 +3516,7 @@ " expected.to.have.status(200);", " if (exclude) {", " pm.response.to.have.header(\"Cache-Status\");", - " pm.expect(pm.response.headers.get(\"Cache-Status\")).to.eql(\"Souin; fwd=uri-miss; key=; detail=CANNOT-HANDLE\");", + " pm.expect(pm.response.headers.get(\"Cache-Status\")).to.eql(\"Souin; fwd=uri-miss; key=*****; detail=CANNOT-HANDLE\");", " } else {", " expected.to.have.header(\"Cache-Status\");", "", diff --git a/pkg/middleware/middleware.go b/pkg/middleware/middleware.go index 4b4295d74..411957c4f 100644 --- a/pkg/middleware/middleware.go +++ b/pkg/middleware/middleware.go @@ -33,6 +33,23 @@ import ( "golang.org/x/sync/singleflight" ) +func reorderStorers(storers []types.Storer, expectedStorers []string) []types.Storer { + if len(expectedStorers) == 0 { + return storers + } + + newStorers := make([]types.Storer, 0) + for _, expectedStorer := range expectedStorers { + for _, storer := range storers { + if storer.Name() == strings.ToUpper(expectedStorer) { + newStorers = append(newStorers, storer) + } + } + } + + return newStorers +} + func NewHTTPCacheHandler(c configurationtypes.AbstractConfigurationInterface) *SouinBaseHandler { if c.GetLogger() == nil { var logLevel zapcore.Level @@ -75,12 +92,14 @@ func NewHTTPCacheHandler(c configurationtypes.AbstractConfigurationInterface) *S } } + storers = reorderStorers(storers, c.GetDefaultCache().GetStorers()) + if len(storers) > 0 { names := []string{} for _, storer := range storers { names = append(names, storer.Name()) } - c.GetLogger().Debugf("You're running Souin with the following storages %s", strings.Join(names, ", ")) + c.GetLogger().Debugf("You're running Souin with the following storages in this order %s", strings.Join(names, ", ")) } } if len(storers) == 0 { @@ -331,24 +350,24 @@ func (s *SouinBaseHandler) Store( } for _, storer := range s.Storers { wg.Add(1) - go func(currentStorer types.Storer) { + go func(currentStorer types.Storer, currentRes http.Response) { defer wg.Done() if currentStorer.SetMultiLevel( cachedKey, variedKey, response, vhs, - res.Header.Get("Etag"), ma, + currentRes.Header.Get("Etag"), ma, variedKey, ) == nil { s.Configuration.GetLogger().Debugf("Stored the key %s in the %s provider", variedKey, currentStorer.Name()) - res.Request = rq + currentRes.Request = rq } else { mu.Lock() fails = append(fails, fmt.Sprintf("; detail=%s-INSERTION-ERROR", currentStorer.Name())) mu.Unlock() } - }(storer) + }(storer, res) } wg.Wait() diff --git a/pkg/rfc/cache_status.go b/pkg/rfc/cache_status.go index f02132fb7..804f8da16 100644 --- a/pkg/rfc/cache_status.go +++ b/pkg/rfc/cache_status.go @@ -67,7 +67,7 @@ func GetCacheKeyFromCtx(currentCtx ctx.Context) string { } } - return "" + return "*****" } // MissCache set miss fwd