httpcache: Index | Files

package rule

import ""


Package Files

chained.go conditional.go header.go not_satisfied.go rule.go satisfied.go validator.go

type PostValidator Uses

type PostValidator func(http.ResponseWriter, *http.Request) bool

PostValidator type is is introduced to implement the second part of the RFC about cache.

Q: What's the difference between this and a PreValidator? A: PreValidator runs BEFORE trying to get the cache, it cares only for the request

and if at least one PreValidator returns false then it just runs the original handler and stop there, at the other hand
a PostValidator runs if all PreValidators returns true and original handler is executed but with a response recorder,
also the PostValidator should return true to store the cached response.
Last, a PostValidator accepts a http.ResponseWriter but internaly it should be `ResponseRecorder`
in order to be able to catch the original handler's response,
the PreValidator checks only for request.

If a function of type of PostValidator returns true then the (shared-always) cache is allowed to be stored.

type PreValidator Uses

type PreValidator func(*http.Request) bool

PreValidator like middleware, executes before the cache action begins, if a callback returns false then this specific cache action, with specific request, is ignored and the real (original) handler is executed instead.

I'll not add all specifications here I'll give the oportunity (public API in the httpcache package-level) to the end-user to specify her/his ignore rules too (ignore-only for now).

Each package, nethttp and fhttp should implement their own encapsulations because of different request object.

One function, accepts the request and returns false if should be denied/ignore, otherwise true. if at least one return false then the original handler will execute as it's and the whole cache action(set & get) should be ignored, it will be never go to the step of post-cache validations.

type Rule Uses

type Rule interface {
    Claim(*http.Request) bool
    Valid(http.ResponseWriter, *http.Request) bool

Rule a superset of validators

func Chained Uses

func Chained(rule Rule, next ...Rule) Rule

Chained returns a new rule which has more than one coming next ruleset

func Conditional Uses

func Conditional(claimPredicate func() bool, validPredicate func() bool) Rule

Conditional returns a new rule witch has conditionals

func DefaultValidator Uses

func DefaultValidator() Rule

DefaultValidator returns a new validator which contains the default pre and post cache validators

func Header(claim ruleset.HeaderPredicate, valid ruleset.HeaderPredicate) Rule

Header returns a new rule witch claims and execute the post validations trough headers

func HeaderClaim Uses

func HeaderClaim(claim ruleset.HeaderPredicate) Rule

HeaderClaim returns a header rule which cares only about claiming (pre-validation)

func HeaderValid Uses

func HeaderValid(valid ruleset.HeaderPredicate) Rule

HeaderValid returns a header rule which cares only about valid (post-validation)

func NotSatisfied Uses

func NotSatisfied() Rule

NotSatisfied returns a rule which allows nothing

func Satisfied Uses

func Satisfied() Rule

Satisfied returns a rule which allows anything, it's usualy the last rule on chained rules if no next rule is given, but it can be used outside of a chain too as a default allow-all rule.

func Validator Uses

func Validator(preValidators []PreValidator, postValidators []PostValidator) Rule

Validator receives the preValidators and postValidators and returns a new Validator rule

Package rule imports 2 packages (graph). Updated 2017-04-12. Refresh now. Tools for package owners. This is an inactive package (no imports and no commits in at least two years).