From 86fd9aa9a67c6a2fc74029d1e9bf42fe9907247d Mon Sep 17 00:00:00 2001 From: GoEdgeLab Date: Fri, 30 Dec 2022 12:04:23 +0800 Subject: [PATCH] =?UTF-8?q?=E5=86=85=E5=AE=B9=E5=8E=8B=E7=BC=A9=E6=94=AF?= =?UTF-8?q?=E6=8C=81=E4=BE=8B=E5=A4=96=E6=89=A9=E5=B1=95=E5=90=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pkg/serverconfigs/http_compression_config.go | 30 +++++++++++++++++--- 1 file changed, 26 insertions(+), 4 deletions(-) diff --git a/pkg/serverconfigs/http_compression_config.go b/pkg/serverconfigs/http_compression_config.go index 6682d6e..85aad38 100644 --- a/pkg/serverconfigs/http_compression_config.go +++ b/pkg/serverconfigs/http_compression_config.go @@ -37,13 +37,15 @@ type HTTPCompressionConfig struct { MaxLength *shared.SizeCapacity `yaml:"maxLength" json:"maxLength"` // 最大压缩对象 MimeTypes []string `yaml:"mimeTypes" json:"mimeTypes"` // 支持的MimeType,支持image/*这样的通配符使用 Extensions []string `yaml:"extensions" json:"extensions"` // 文件扩展名,包含点符号,不区分大小写 + ExceptExtensions []string `yaml:"exceptExtensions" json:"exceptExtensions"` // 例外扩展名 Conds *shared.HTTPRequestCondsConfig `yaml:"conds" json:"conds"` // 匹配条件 EnablePartialContent bool `yaml:"enablePartialContent" json:"enablePartialContent"` // 支持PartialContent压缩 - minLength int64 - maxLength int64 - mimeTypeRules []*shared.MimeTypeRule - extensions []string + minLength int64 + maxLength int64 + mimeTypeRules []*shared.MimeTypeRule + extensions []string + exceptExtensions []string types []HTTPCompressionType @@ -89,6 +91,15 @@ func (this *HTTPCompressionConfig) Init() error { this.extensions = append(this.extensions, ext) } + this.exceptExtensions = []string{} + for _, ext := range this.ExceptExtensions { + ext = strings.ToLower(ext) + if len(ext) > 0 && ext[0] != '.' { + ext = "." + ext + } + this.exceptExtensions = append(this.exceptExtensions, ext) + } + if this.Gzip != nil { err := this.Gzip.Init() if err != nil { @@ -174,6 +185,17 @@ func (this *HTTPCompressionConfig) MatchResponse(mimeType string, contentLength return false } + // except extensions + if len(this.exceptExtensions) > 0 { + if len(requestExt) > 0 { + for _, ext := range this.exceptExtensions { + if ext == requestExt { + return false + } + } + } + } + // extensions if len(this.extensions) > 0 { if len(requestExt) > 0 {