diff --git a/pkg/serverconfigs/http_compression_config.go b/pkg/serverconfigs/http_compression_config.go index 85aad38..3872f00 100644 --- a/pkg/serverconfigs/http_compression_config.go +++ b/pkg/serverconfigs/http_compression_config.go @@ -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 +}