From 76bd0abb9423ffa802424cd0769871e4d9f0b11c Mon Sep 17 00:00:00 2001 From: GoEdgeLab Date: Wed, 9 Jun 2021 17:15:12 +0800 Subject: [PATCH] =?UTF-8?q?=E7=BC=93=E5=AD=98=E6=9D=A1=E4=BB=B6=E6=94=AF?= =?UTF-8?q?=E6=8C=81=E5=8F=8D=E5=90=91=E5=8C=B9=E9=85=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pkg/serverconfigs/http_cache_ref.go | 2 ++ pkg/serverconfigs/shared/http_request_cond.go | 13 +++++++++++-- .../shared/http_request_conds_config.go | 12 ++++++------ 3 files changed, 19 insertions(+), 8 deletions(-) diff --git a/pkg/serverconfigs/http_cache_ref.go b/pkg/serverconfigs/http_cache_ref.go index 49fb1d9..aa8e94f 100644 --- a/pkg/serverconfigs/http_cache_ref.go +++ b/pkg/serverconfigs/http_cache_ref.go @@ -26,6 +26,8 @@ type HTTPCacheRef struct { CachePolicy *HTTPCachePolicy `yaml:"cachePolicy" json:"cachePolicy"` + IsReverse bool `yaml:"isReverse" json:"isReverse"` // 是否为反向条件,反向条件的不缓存 + lifeSeconds int64 maxSize int64 uppercaseSkipCacheControlValues []string diff --git a/pkg/serverconfigs/shared/http_request_cond.go b/pkg/serverconfigs/shared/http_request_cond.go index 047d867..80e9ea8 100644 --- a/pkg/serverconfigs/shared/http_request_cond.go +++ b/pkg/serverconfigs/shared/http_request_cond.go @@ -26,8 +26,9 @@ type HTTPRequestCond struct { // ${arg.name}, ${requestPath} Param string `yaml:"param" json:"param"` - Operator RequestCondOperator `yaml:"operator" json:"operator"` // 运算符 - Value string `yaml:"value" json:"value"` // 对比值 + Operator RequestCondOperator `yaml:"operator" json:"operator"` // 运算符 + Value string `yaml:"value" json:"value"` // 对比值 + IsReverse bool `yaml:"isReverse" json:"isReverse"` // 是否反向匹配 isInt bool isFloat bool @@ -136,6 +137,14 @@ func (this *HTTPRequestCond) Init() error { // Match 将此条件应用于请求,检查是否匹配 func (this *HTTPRequestCond) Match(formatter func(source string) string) bool { + b := this.match(formatter) + if this.IsReverse { + return !b + } + return b +} + +func (this *HTTPRequestCond) match(formatter func(source string) string) bool { paramValue := formatter(this.Param) switch this.Operator { case RequestCondOperatorRegexp: diff --git a/pkg/serverconfigs/shared/http_request_conds_config.go b/pkg/serverconfigs/shared/http_request_conds_config.go index e5fb5b5..12d93dc 100644 --- a/pkg/serverconfigs/shared/http_request_conds_config.go +++ b/pkg/serverconfigs/shared/http_request_conds_config.go @@ -1,6 +1,6 @@ package shared -// 条件配置 +// HTTPRequestCondsConfig 条件配置 // 数据结构:conds -> []groups -> []cond type HTTPRequestCondsConfig struct { IsOn bool `yaml:"isOn" json:"isOn"` @@ -11,7 +11,7 @@ type HTTPRequestCondsConfig struct { hasResponseConds bool } -// 初始化 +// Init 初始化 func (this *HTTPRequestCondsConfig) Init() error { if len(this.Connector) == 0 { this.Connector = "or" @@ -39,7 +39,7 @@ func (this *HTTPRequestCondsConfig) Init() error { return nil } -// 判断请求是否匹配 +// MatchRequest 判断请求是否匹配 func (this *HTTPRequestCondsConfig) MatchRequest(formatter func(s string) string) bool { if !this.IsOn && len(this.Groups) == 0 { return true @@ -61,7 +61,7 @@ func (this *HTTPRequestCondsConfig) MatchRequest(formatter func(s string) string return ok } -// 判断响应是否匹配 +// MatchResponse 判断响应是否匹配 func (this *HTTPRequestCondsConfig) MatchResponse(formatter func(s string) string) bool { if !this.IsOn && len(this.Groups) == 0 { return true @@ -83,12 +83,12 @@ func (this *HTTPRequestCondsConfig) MatchResponse(formatter func(s string) strin return ok } -// 判断是否有请求条件 +// HasRequestConds 判断是否有请求条件 func (this *HTTPRequestCondsConfig) HasRequestConds() bool { return this.hasRequestConds } -// 判断是否有响应条件 +// HasResponseConds 判断是否有响应条件 func (this *HTTPRequestCondsConfig) HasResponseConds() bool { return this.hasResponseConds }