From 50232d4938ccc15e87d32079ea2421ebea4cce01 Mon Sep 17 00:00:00 2001 From: GoEdgeLab Date: Thu, 24 Feb 2022 20:13:05 +0800 Subject: [PATCH] =?UTF-8?q?=E9=BB=98=E8=AE=A4=E4=B8=8D=E5=90=8C=E6=AD=A5?= =?UTF-8?q?=E5=86=99=E5=85=A5=E5=8E=8B=E7=BC=A9=E7=BC=93=E5=AD=98/?= =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=98=AF=E5=90=A6=E5=90=8C=E6=AD=A5=E5=86=99?= =?UTF-8?q?=E5=85=A5=E5=8E=8B=E7=BC=A9=E7=BC=93=E5=AD=98=E8=AE=BE=E7=BD=AE?= =?UTF-8?q?/=E5=8E=BB=E9=99=A4=E9=BB=98=E8=AE=A4content-type=E7=B1=BB?= =?UTF-8?q?=E5=9E=8B=E8=AE=BE=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- internal/nodes/http_writer.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/internal/nodes/http_writer.go b/internal/nodes/http_writer.go index 3099086..bf6ae15 100644 --- a/internal/nodes/http_writer.go +++ b/internal/nodes/http_writer.go @@ -387,10 +387,6 @@ func (this *HTTPWriter) PrepareCompression(resp *http.Response, size int64) { // 尺寸和类型 var contentType = this.Header().Get("Content-Type") - if len(contentType) == 0 { - // 如果没有显式设置Content-Type,我们就认为是 text/html - contentType = "text/html" - } if !this.compressionConfig.MatchResponse(contentType, size, filepath.Ext(this.req.Path()), this.req.Format) { return } @@ -427,7 +423,11 @@ func (this *HTTPWriter) PrepareCompression(resp *http.Response, size int64) { header.Del("Content-Length") // compression cache writer - if !this.isPartial && this.cacheStorage != nil && (this.cacheReader != nil || this.cacheWriter != nil) && !this.webpIsEncoding { + // 只有在本身内容已经缓存的情况下才会写入缓存,防止同时写入缓存导致IO负载升高 + if !this.isPartial && + this.cacheStorage != nil && + (this.cacheReader != nil || (this.cacheStorage.Policy().SyncCompressionCache && this.cacheWriter != nil)) && + !this.webpIsEncoding { var cacheKey = "" var expiredAt int64 = 0