From a95ac1599f0a718a8afec0524b4c0371ca5fa923 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=98=E7=A5=A5=E8=B6=85?= Date: Sun, 3 Oct 2021 18:01:12 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96WebP+=E7=BC=93=E5=AD=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pkg/serverconfigs/image_webp_config.go | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/pkg/serverconfigs/image_webp_config.go b/pkg/serverconfigs/image_webp_config.go index d6fb2e2..0d998f4 100644 --- a/pkg/serverconfigs/image_webp_config.go +++ b/pkg/serverconfigs/image_webp_config.go @@ -121,6 +121,27 @@ func (this *WebPImageConfig) MatchResponse(mimeType string, contentLength int64, return false } +// MatchRequest 是否匹配请求 +func (this *WebPImageConfig) MatchRequest(requestExt string, formatter shared.Formatter) bool { + if this.Conds != nil && formatter != nil { + if !this.Conds.MatchRequest(formatter) { + return false + } + } + + // extensions + if len(this.mimeTypeRules) == 0 && len(this.extensions) > 0 && len(requestExt) > 0 { + for _, ext := range this.extensions { + if ext == requestExt { + return true + } + } + return false + } + + return true +} + // MatchAccept 检查客户端是否能接受WebP func (this *WebPImageConfig) MatchAccept(acceptContentTypes string) bool { var t = "image/webp"