Something went wrong. Try again.
forked from darkweak/souin
Something went wrong. Try again.
12345678910111213141516171819202122232425262728293031323334353637383940414243444546package context
import ( "context" "net/http"
"github.com/darkweak/souin/configurationtypes")
const SupportedMethod ctxKey = "souin_ctx.SUPPORTED_METHOD"
var defaultVerbs []string = []string{http.MethodGet, http.MethodHead}
type methodContext struct { allowedVerbs []string custom bool}
func (*methodContext) SetContextWithBaseRequest(req *http.Request, _ *http.Request) *http.Request { return req}
func (m *methodContext) SetupContext(c configurationtypes.AbstractConfigurationInterface) { m.allowedVerbs = defaultVerbs if len(c.GetDefaultCache().GetAllowedHTTPVerbs()) != 0 { m.allowedVerbs = c.GetDefaultCache().GetAllowedHTTPVerbs() m.custom = true } c.GetLogger().Debugf("Allow %d method(s). %v.", len(m.allowedVerbs), m.allowedVerbs)}
func (m *methodContext) SetContext(req *http.Request) *http.Request { v := false
for _, a := range m.allowedVerbs { if req.Method == a { v = true break } }
return req.WithContext(context.WithValue(req.Context(), SupportedMethod, v))}
var _ ctx = (*methodContext)(nil)