内容压缩功能增加“例外URL“和“限制URL”设置

This commit is contained in:
GoEdgeLab
2024-04-17 13:55:10 +08:00
parent d453416d5f
commit 9a9d39a323

View File

@@ -41,6 +41,9 @@ type HTTPCompressionConfig struct {
Conds *shared.HTTPRequestCondsConfig `yaml:"conds" json:"conds"` // 匹配条件
EnablePartialContent bool `yaml:"enablePartialContent" json:"enablePartialContent"` // 支持PartialContent压缩
OnlyURLPatterns []*shared.URLPattern `yaml:"onlyURLPatterns" json:"onlyURLPatterns"` // 仅限的URL
ExceptURLPatterns []*shared.URLPattern `yaml:"exceptURLPatterns" json:"exceptURLPatterns"` // 排除的URL
minLength int64
maxLength int64
mimeTypeRules []*shared.MimeTypeRule
@@ -151,6 +154,21 @@ func (this *HTTPCompressionConfig) Init() error {
}
}
// url patterns
for _, pattern := range this.ExceptURLPatterns {
err := pattern.Init()
if err != nil {
return err
}
}
for _, pattern := range this.OnlyURLPatterns {
err := pattern.Init()
if err != nil {
return err
}
}
return nil
}
@@ -279,3 +297,26 @@ func (this *HTTPCompressionConfig) MatchAcceptEncoding(acceptEncodings string) (
return "", "", false
}
func (this *HTTPCompressionConfig) MatchURL(url string) bool {
// except
if len(this.ExceptURLPatterns) > 0 {
for _, pattern := range this.ExceptURLPatterns {
if pattern.Match(url) {
return false
}
}
}
// only
if len(this.OnlyURLPatterns) > 0 {
for _, pattern := range this.OnlyURLPatterns {
if pattern.Match(url) {
return true
}
}
return false
}
return true
}