-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(chore): add mode to bypass RFC (#348)
* feat(chore): add mode to bypass RFC * fix(e2e): update JSON configuration * fix: souin. prefix on context keys and throw error on caddy directive error * fix(plugins): retrieve caddy mode argument, support inmemory badger configuration option * Update documentation
- Loading branch information
Showing
37 changed files
with
1,629 additions
and
420 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package context | ||
|
||
import ( | ||
"context" | ||
"net/http" | ||
|
||
"github.com/darkweak/souin/configurationtypes" | ||
) | ||
|
||
const Mode ctxKey = "souin_ctx.MODE" | ||
|
||
type ModeContext struct { | ||
Strict, Bypass_request, Bypass_response bool | ||
} | ||
|
||
func (mc *ModeContext) SetupContext(c configurationtypes.AbstractConfigurationInterface) { | ||
mode := c.GetDefaultCache().GetMode() | ||
mc.Bypass_request = mode == "bypass" || mode == "bypass_request" | ||
mc.Bypass_response = mode == "bypass" || mode == "bypass_response" | ||
mc.Strict = !mc.Bypass_request && !mc.Bypass_response | ||
c.GetLogger().Sugar().Debugf("The cache logic will run as %s: %+v", mode, mc) | ||
} | ||
|
||
func (mc *ModeContext) SetContext(req *http.Request) *http.Request { | ||
return req.WithContext(context.WithValue(req.Context(), Mode, mc)) | ||
} | ||
|
||
var _ ctx = (*cacheContext)(nil) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package context | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/darkweak/souin/configurationtypes" | ||
"github.com/darkweak/souin/plugins/souin/configuration" | ||
"go.uber.org/zap" | ||
) | ||
|
||
func Test_ModeContext_SetupContext(t *testing.T) { | ||
dc := configurationtypes.DefaultCache{} | ||
c := configuration.Configuration{ | ||
DefaultCache: &dc, | ||
} | ||
c.SetLogger(zap.NewNop()) | ||
ctx := ModeContext{} | ||
|
||
ctx.SetupContext(&c) | ||
if ctx.Bypass_request || ctx.Bypass_response || !ctx.Strict { | ||
t.Error("The context must be strict and must not bypass either response or request.") | ||
} | ||
|
||
c.DefaultCache.Mode = "bypass" | ||
ctx = ModeContext{} | ||
ctx.SetupContext(&c) | ||
if !ctx.Bypass_request || !ctx.Bypass_response || ctx.Strict { | ||
t.Error("The context must bypass either response and request.") | ||
} | ||
|
||
c.DefaultCache.Mode = "bypass_request" | ||
ctx = ModeContext{} | ||
ctx.SetupContext(&c) | ||
if !ctx.Bypass_request || ctx.Bypass_response || ctx.Strict { | ||
t.Error("The context must bypass request only.") | ||
} | ||
|
||
c.DefaultCache.Mode = "bypass_response" | ||
ctx = ModeContext{} | ||
ctx.SetupContext(&c) | ||
if ctx.Bypass_request || !ctx.Bypass_response || ctx.Strict { | ||
t.Error("The context must bypass response only.") | ||
} | ||
|
||
c.DefaultCache.Mode = "strict" | ||
ctx = ModeContext{} | ||
ctx.SetupContext(&c) | ||
if ctx.Bypass_request || ctx.Bypass_response || !ctx.Strict { | ||
t.Error("The context must be strict.") | ||
} | ||
|
||
c.DefaultCache.Mode = "default_value" | ||
ctx = ModeContext{} | ||
ctx.SetupContext(&c) | ||
if ctx.Bypass_request || ctx.Bypass_response || !ctx.Strict { | ||
t.Error("The context must be strict.") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.