1
0
mirror of https://github.com/kataras/iris.git synced 2025-12-21 11:57:02 +00:00

(#1554) Add support for all common compressions (write and read)

- Remove the context.Context interface and export the *context, the iris.Context now points to the pointer\nSupport compression and rate limiting in the FileServer\nBit of code organisation


Former-commit-id: ad1c61bf968059510c6be9e7f2cceec7da70ba17
This commit is contained in:
Gerasimos (Makis) Maropoulos
2020-07-10 23:21:09 +03:00
parent 645da2b2ef
commit 0f113dfcda
112 changed files with 2119 additions and 3390 deletions

View File

@@ -1,8 +1,6 @@
package rule
import (
"github.com/kataras/iris/v12/context"
)
import "github.com/kataras/iris/v12/context"
// Validators are introduced to implement the RFC about cache (https://tools.ietf.org/html/rfc7234#section-1.1).
@@ -18,7 +16,7 @@ import (
// 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 PreValidator func(context.Context) bool
type PreValidator func(*context.Context) bool
// PostValidator type is is introduced to implement the second part of the RFC about cache.
//
@@ -32,7 +30,7 @@ type PreValidator func(context.Context) bool
// 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 PostValidator func(context.Context) bool
type PostValidator func(*context.Context) bool
// validatorRule is a rule witch receives PreValidators and PostValidators
// it's a 'complete set of rules', you can call it as a Responsible Validator,
@@ -68,7 +66,7 @@ func Validator(preValidators []PreValidator, postValidators []PostValidator) Rul
// Claim returns true if incoming request can claim for a cached handler
// the original handler should run as it is and exit
func (v *validatorRule) Claim(ctx context.Context) bool {
func (v *validatorRule) Claim(ctx *context.Context) bool {
// 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 {
@@ -82,7 +80,7 @@ func (v *validatorRule) Claim(ctx context.Context) bool {
// 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
func (v *validatorRule) Valid(ctx context.Context) bool {
func (v *validatorRule) Valid(ctx *context.Context) bool {
// check if it's a valid response, if it's not then just return.
for _, valid := range v.postValidators {
if !valid(ctx) {