From e977d25e27c5fb0954d6ae63c0c84f8cbc391a7d Mon Sep 17 00:00:00 2001 From: GoEdgeLab Date: Sun, 18 Apr 2021 22:17:17 +0800 Subject: [PATCH] =?UTF-8?q?=E7=BC=93=E5=AD=98=E8=AE=BE=E7=BD=AE=E4=B8=AD?= =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E2=80=9C=E6=94=AF=E6=8C=81=E5=88=86=E7=89=87?= =?UTF-8?q?=E5=86=85=E5=AE=B9=E2=80=9D=E9=80=89=E9=A1=B9=EF=BC=8C=E7=94=A8?= =?UTF-8?q?=E6=9D=A5=E6=94=AF=E6=8C=81Chunked=E5=86=85=E5=AE=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- internal/nodes/http_writer.go | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/internal/nodes/http_writer.go b/internal/nodes/http_writer.go index adefdbc..050fc41 100644 --- a/internal/nodes/http_writer.go +++ b/internal/nodes/http_writer.go @@ -304,7 +304,7 @@ func (this *HTTPWriter) prepareGzip(size int64) { // 准备缓存 func (this *HTTPWriter) prepareCache(size int64) { - if this.writer == nil || size <= 0 { + if this.writer == nil { return } @@ -319,10 +319,16 @@ func (this *HTTPWriter) prepareCache(size int64) { } cacheRef := this.req.cacheRef - if cacheRef == nil || - !cacheRef.IsOn || - (cacheRef.MaxSizeBytes() > 0 && size > cacheRef.MaxSizeBytes()) || - (cachePolicy.MaxSizeBytes() > 0 && size > cachePolicy.MaxSizeBytes()) { + if cacheRef == nil || !cacheRef.IsOn { + return + } + + // 如果允许 ChunkedEncoding,就无需尺寸的判断,因为此时的 size 为 -1 + if !cacheRef.AllowChunkedEncoding && size < 0 { + return + } + if size >= 0 && ((cacheRef.MaxSizeBytes() > 0 && size > cacheRef.MaxSizeBytes()) || + (cachePolicy.MaxSizeBytes() > 0 && size > cachePolicy.MaxSizeBytes())) { return }