From 9a9d39a32378719e072bc6a61e5dec53c34b8659 Mon Sep 17 00:00:00 2001 From: GoEdgeLab Date: Wed, 17 Apr 2024 13:55:10 +0800 Subject: [PATCH] =?UTF-8?q?=E5=86=85=E5=AE=B9=E5=8E=8B=E7=BC=A9=E5=8A=9F?= =?UTF-8?q?=E8=83=BD=E5=A2=9E=E5=8A=A0=E2=80=9C=E4=BE=8B=E5=A4=96URL?= =?UTF-8?q?=E2=80=9C=E5=92=8C=E2=80=9C=E9=99=90=E5=88=B6URL=E2=80=9D?= =?UTF-8?q?=E8=AE=BE=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pkg/serverconfigs/http_compression_config.go | 41 ++++++++++++++++++++ 1 file changed, 41 insertions(+) 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 +}