Publish the new version :airplane: | Look description please!
# FAQ
### Looking for free support?
http://support.iris-go.com
https://kataras.rocket.chat/channel/iris
### Looking for previous versions?
https://github.com/kataras/iris#version
### Should I upgrade my Iris?
Developers are not forced to upgrade if they don't really need it. Upgrade whenever you feel ready.
> Iris uses the [vendor directory](https://docs.google.com/document/d/1Bz5-UB7g2uPBdOx-rw5t9MxJwkfpx90cqG9AFL0JAYo) feature, so you get truly reproducible builds, as this method guards against upstream renames and deletes.
**How to upgrade**: Open your command-line and execute this command: `go get -u github.com/kataras/iris`.
For further installation support, please click [here](http://support.iris-go.com/d/16-how-to-install-iris-web-framework).
### About our new home page
http://iris-go.com
Thanks to [Santosh Anand](https://github.com/santoshanand) the http://iris-go.com has been upgraded and it's really awesome!
[Santosh](https://github.com/santoshanand) is a freelancer, he has a great knowledge of nodejs and express js, Android, iOS, React Native, Vue.js etc, if you need a developer to find or create a solution for your problem or task, please contact with him.
The amount of the next two or three donations you'll send they will be immediately transferred to his own account balance, so be generous please!
Read more at https://github.com/kataras/iris/blob/master/HISTORY.md
Former-commit-id: eec2d71bbe011d6b48d2526eb25919e36e5ad94e
2017-06-03 22:22:52 +02:00
|
|
|
package rule
|
|
|
|
|
2020-07-10 22:21:09 +02:00
|
|
|
import "github.com/kataras/iris/v12/context"
|
Publish the new version :airplane: | Look description please!
# FAQ
### Looking for free support?
http://support.iris-go.com
https://kataras.rocket.chat/channel/iris
### Looking for previous versions?
https://github.com/kataras/iris#version
### Should I upgrade my Iris?
Developers are not forced to upgrade if they don't really need it. Upgrade whenever you feel ready.
> Iris uses the [vendor directory](https://docs.google.com/document/d/1Bz5-UB7g2uPBdOx-rw5t9MxJwkfpx90cqG9AFL0JAYo) feature, so you get truly reproducible builds, as this method guards against upstream renames and deletes.
**How to upgrade**: Open your command-line and execute this command: `go get -u github.com/kataras/iris`.
For further installation support, please click [here](http://support.iris-go.com/d/16-how-to-install-iris-web-framework).
### About our new home page
http://iris-go.com
Thanks to [Santosh Anand](https://github.com/santoshanand) the http://iris-go.com has been upgraded and it's really awesome!
[Santosh](https://github.com/santoshanand) is a freelancer, he has a great knowledge of nodejs and express js, Android, iOS, React Native, Vue.js etc, if you need a developer to find or create a solution for your problem or task, please contact with him.
The amount of the next two or three donations you'll send they will be immediately transferred to his own account balance, so be generous please!
Read more at https://github.com/kataras/iris/blob/master/HISTORY.md
Former-commit-id: eec2d71bbe011d6b48d2526eb25919e36e5ad94e
2017-06-03 22:22:52 +02:00
|
|
|
|
|
|
|
// Validators are introduced to implement the RFC about cache (https://tools.ietf.org/html/rfc7234#section-1.1).
|
|
|
|
|
|
|
|
// 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 opportunity (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.
|
2020-07-10 22:21:09 +02:00
|
|
|
type PreValidator func(*context.Context) bool
|
Publish the new version :airplane: | Look description please!
# FAQ
### Looking for free support?
http://support.iris-go.com
https://kataras.rocket.chat/channel/iris
### Looking for previous versions?
https://github.com/kataras/iris#version
### Should I upgrade my Iris?
Developers are not forced to upgrade if they don't really need it. Upgrade whenever you feel ready.
> Iris uses the [vendor directory](https://docs.google.com/document/d/1Bz5-UB7g2uPBdOx-rw5t9MxJwkfpx90cqG9AFL0JAYo) feature, so you get truly reproducible builds, as this method guards against upstream renames and deletes.
**How to upgrade**: Open your command-line and execute this command: `go get -u github.com/kataras/iris`.
For further installation support, please click [here](http://support.iris-go.com/d/16-how-to-install-iris-web-framework).
### About our new home page
http://iris-go.com
Thanks to [Santosh Anand](https://github.com/santoshanand) the http://iris-go.com has been upgraded and it's really awesome!
[Santosh](https://github.com/santoshanand) is a freelancer, he has a great knowledge of nodejs and express js, Android, iOS, React Native, Vue.js etc, if you need a developer to find or create a solution for your problem or task, please contact with him.
The amount of the next two or three donations you'll send they will be immediately transferred to his own account balance, so be generous please!
Read more at https://github.com/kataras/iris/blob/master/HISTORY.md
Former-commit-id: eec2d71bbe011d6b48d2526eb25919e36e5ad94e
2017-06-03 22:22:52 +02:00
|
|
|
|
|
|
|
// 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 context
|
|
|
|
// 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.
|
2020-07-10 22:21:09 +02:00
|
|
|
type PostValidator func(*context.Context) bool
|
Publish the new version :airplane: | Look description please!
# FAQ
### Looking for free support?
http://support.iris-go.com
https://kataras.rocket.chat/channel/iris
### Looking for previous versions?
https://github.com/kataras/iris#version
### Should I upgrade my Iris?
Developers are not forced to upgrade if they don't really need it. Upgrade whenever you feel ready.
> Iris uses the [vendor directory](https://docs.google.com/document/d/1Bz5-UB7g2uPBdOx-rw5t9MxJwkfpx90cqG9AFL0JAYo) feature, so you get truly reproducible builds, as this method guards against upstream renames and deletes.
**How to upgrade**: Open your command-line and execute this command: `go get -u github.com/kataras/iris`.
For further installation support, please click [here](http://support.iris-go.com/d/16-how-to-install-iris-web-framework).
### About our new home page
http://iris-go.com
Thanks to [Santosh Anand](https://github.com/santoshanand) the http://iris-go.com has been upgraded and it's really awesome!
[Santosh](https://github.com/santoshanand) is a freelancer, he has a great knowledge of nodejs and express js, Android, iOS, React Native, Vue.js etc, if you need a developer to find or create a solution for your problem or task, please contact with him.
The amount of the next two or three donations you'll send they will be immediately transferred to his own account balance, so be generous please!
Read more at https://github.com/kataras/iris/blob/master/HISTORY.md
Former-commit-id: eec2d71bbe011d6b48d2526eb25919e36e5ad94e
2017-06-03 22:22:52 +02:00
|
|
|
|
|
|
|
// validatorRule is a rule witch receives PreValidators and PostValidators
|
|
|
|
// it's a 'complete set of rules', you can call it as a Responsible Validator,
|
|
|
|
// it's used when you the user wants to check for special things inside a request and a response.
|
|
|
|
type validatorRule struct {
|
|
|
|
// preValidators a list of PreValidator functions, execute before real cache begins
|
|
|
|
// if at least one of them returns false then the original handler will execute as it's
|
|
|
|
// and the whole cache action(set & get) will be skipped for this specific client's request.
|
|
|
|
//
|
|
|
|
// Read-only 'runtime'
|
|
|
|
preValidators []PreValidator
|
|
|
|
|
|
|
|
// postValidators a list of PostValidator functions, execute after the original handler is executed with the response recorder
|
|
|
|
// and exactly before this cached response is saved,
|
|
|
|
// if at least one of them returns false then the response will be not saved for this specific client's request.
|
|
|
|
//
|
|
|
|
// Read-only 'runtime'
|
|
|
|
postValidators []PostValidator
|
|
|
|
}
|
|
|
|
|
|
|
|
var _ Rule = &validatorRule{}
|
|
|
|
|
|
|
|
// DefaultValidator returns a new validator which contains the default pre and post cache validators
|
|
|
|
func DefaultValidator() Rule { return Validator(nil, nil) }
|
|
|
|
|
|
|
|
// Validator receives the preValidators and postValidators and returns a new Validator rule
|
|
|
|
func Validator(preValidators []PreValidator, postValidators []PostValidator) Rule {
|
|
|
|
return &validatorRule{
|
|
|
|
preValidators: preValidators,
|
|
|
|
postValidators: postValidators,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Claim returns true if incoming request can claim for a cached handler
|
|
|
|
// the original handler should run as it is and exit
|
2020-07-10 22:21:09 +02:00
|
|
|
func (v *validatorRule) Claim(ctx *context.Context) bool {
|
Publish the new version :airplane: | Look description please!
# FAQ
### Looking for free support?
http://support.iris-go.com
https://kataras.rocket.chat/channel/iris
### Looking for previous versions?
https://github.com/kataras/iris#version
### Should I upgrade my Iris?
Developers are not forced to upgrade if they don't really need it. Upgrade whenever you feel ready.
> Iris uses the [vendor directory](https://docs.google.com/document/d/1Bz5-UB7g2uPBdOx-rw5t9MxJwkfpx90cqG9AFL0JAYo) feature, so you get truly reproducible builds, as this method guards against upstream renames and deletes.
**How to upgrade**: Open your command-line and execute this command: `go get -u github.com/kataras/iris`.
For further installation support, please click [here](http://support.iris-go.com/d/16-how-to-install-iris-web-framework).
### About our new home page
http://iris-go.com
Thanks to [Santosh Anand](https://github.com/santoshanand) the http://iris-go.com has been upgraded and it's really awesome!
[Santosh](https://github.com/santoshanand) is a freelancer, he has a great knowledge of nodejs and express js, Android, iOS, React Native, Vue.js etc, if you need a developer to find or create a solution for your problem or task, please contact with him.
The amount of the next two or three donations you'll send they will be immediately transferred to his own account balance, so be generous please!
Read more at https://github.com/kataras/iris/blob/master/HISTORY.md
Former-commit-id: eec2d71bbe011d6b48d2526eb25919e36e5ad94e
2017-06-03 22:22:52 +02:00
|
|
|
// check for pre-cache validators, if at least one of them return false
|
|
|
|
// for this specific request, then skip the whole cache
|
|
|
|
for _, shouldProcess := range v.preValidators {
|
|
|
|
if !shouldProcess(ctx) {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
|
|
|
// Valid returns true if incoming request and post-response from the original handler
|
|
|
|
// is valid to be store to the cache, if not(false) then the consumer should just exit
|
|
|
|
// otherwise(true) the consumer should store the cached response
|
2020-07-10 22:21:09 +02:00
|
|
|
func (v *validatorRule) Valid(ctx *context.Context) bool {
|
Publish the new version :airplane: | Look description please!
# FAQ
### Looking for free support?
http://support.iris-go.com
https://kataras.rocket.chat/channel/iris
### Looking for previous versions?
https://github.com/kataras/iris#version
### Should I upgrade my Iris?
Developers are not forced to upgrade if they don't really need it. Upgrade whenever you feel ready.
> Iris uses the [vendor directory](https://docs.google.com/document/d/1Bz5-UB7g2uPBdOx-rw5t9MxJwkfpx90cqG9AFL0JAYo) feature, so you get truly reproducible builds, as this method guards against upstream renames and deletes.
**How to upgrade**: Open your command-line and execute this command: `go get -u github.com/kataras/iris`.
For further installation support, please click [here](http://support.iris-go.com/d/16-how-to-install-iris-web-framework).
### About our new home page
http://iris-go.com
Thanks to [Santosh Anand](https://github.com/santoshanand) the http://iris-go.com has been upgraded and it's really awesome!
[Santosh](https://github.com/santoshanand) is a freelancer, he has a great knowledge of nodejs and express js, Android, iOS, React Native, Vue.js etc, if you need a developer to find or create a solution for your problem or task, please contact with him.
The amount of the next two or three donations you'll send they will be immediately transferred to his own account balance, so be generous please!
Read more at https://github.com/kataras/iris/blob/master/HISTORY.md
Former-commit-id: eec2d71bbe011d6b48d2526eb25919e36e5ad94e
2017-06-03 22:22:52 +02:00
|
|
|
// check if it's a valid response, if it's not then just return.
|
|
|
|
for _, valid := range v.postValidators {
|
|
|
|
if !valid(ctx) {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true
|
|
|
|
}
|