mirror of
https://github.com/TeaOSLab/EdgeCommon.git
synced 2026-02-16 04:25:38 +08:00
实现缓存策略的部分功能
This commit is contained in:
@@ -17,7 +17,7 @@ func (this *HTTPRequestCondGroup) Init() error {
|
||||
if len(this.Connector) == 0 {
|
||||
this.Connector = "or"
|
||||
}
|
||||
|
||||
|
||||
if len(this.Conds) > 0 {
|
||||
for _, cond := range this.Conds {
|
||||
err := cond.Init()
|
||||
@@ -43,6 +43,14 @@ func (this *HTTPRequestCondGroup) MatchResponse(formatter func(source string) st
|
||||
return this.match(this.responseConds, formatter)
|
||||
}
|
||||
|
||||
func (this *HTTPRequestCondGroup) HasRequestConds() bool {
|
||||
return len(this.requestConds) > 0
|
||||
}
|
||||
|
||||
func (this *HTTPRequestCondGroup) HasResponseConds() bool {
|
||||
return len(this.responseConds) > 0
|
||||
}
|
||||
|
||||
func (this *HTTPRequestCondGroup) match(conds []*HTTPRequestCond, formatter func(source string) string) bool {
|
||||
if !this.IsOn || len(conds) == 0 {
|
||||
return !this.IsReverse
|
||||
|
||||
@@ -6,6 +6,9 @@ type HTTPRequestCondsConfig struct {
|
||||
IsOn bool `yaml:"isOn" json:"isOn"`
|
||||
Connector string `yaml:"connector" json:"connector"`
|
||||
Groups []*HTTPRequestCondGroup `yaml:"groups" json:"groups"`
|
||||
|
||||
hasRequestConds bool
|
||||
hasResponseConds bool
|
||||
}
|
||||
|
||||
// 初始化
|
||||
@@ -21,6 +24,18 @@ func (this *HTTPRequestCondsConfig) Init() error {
|
||||
}
|
||||
}
|
||||
|
||||
// 是否有请求条件
|
||||
for _, group := range this.Groups {
|
||||
if group.IsOn {
|
||||
if group.HasRequestConds() {
|
||||
this.hasRequestConds = true
|
||||
}
|
||||
if group.HasResponseConds() {
|
||||
this.hasResponseConds = true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -67,3 +82,13 @@ func (this *HTTPRequestCondsConfig) MatchResponse(formatter func(s string) strin
|
||||
}
|
||||
return ok
|
||||
}
|
||||
|
||||
// 判断是否有请求条件
|
||||
func (this *HTTPRequestCondsConfig) HasRequestConds() bool {
|
||||
return this.hasRequestConds
|
||||
}
|
||||
|
||||
// 判断是否有响应条件
|
||||
func (this *HTTPRequestCondsConfig) HasResponseConds() bool {
|
||||
return this.hasResponseConds
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user