From 28e7664eb70c30bd64103d08cf9f7c55c7ab635a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=98=E7=A5=A5=E8=B6=85?= Date: Sun, 12 Mar 2023 16:09:06 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=BA=90=E7=AB=99=E9=87=8D?= =?UTF-8?q?=E8=AF=95=E6=97=B6=E5=8F=AF=E8=83=BD=E4=BA=A7=E7=94=9F=E7=9A=84?= =?UTF-8?q?file=20is=20writing=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- internal/nodes/http_writer.go | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/internal/nodes/http_writer.go b/internal/nodes/http_writer.go index 94392ee..c773c78 100644 --- a/internal/nodes/http_writer.go +++ b/internal/nodes/http_writer.go @@ -104,6 +104,18 @@ func NewHTTPWriter(req *HTTPRequest, httpResponseWriter http.ResponseWriter) *HT // Prepare 准备输出 func (this *HTTPWriter) Prepare(resp *http.Response, size int64, status int, enableCache bool) (delayHeaders bool) { + // 清理以前数据,防止重试时发生异常错误 + if this.compressionCacheWriter != nil { + _ = this.compressionCacheWriter.Discard() + this.compressionCacheWriter = nil + } + + if this.cacheWriter != nil { + _ = this.cacheWriter.Discard() + this.cacheWriter = nil + } + + // 新的请求相关数据 this.size = size this.statusCode = status @@ -334,6 +346,9 @@ func (this *HTTPWriter) PrepareCache(resp *http.Response, size int64) { } return } + if this.cacheWriter != nil { + _ = this.cacheWriter.Discard() + } this.cacheWriter = cacheWriter if this.isPartial { @@ -696,6 +711,9 @@ func (this *HTTPWriter) PrepareCompression(resp *http.Response, size int64) { } if compressionCacheWriter != nil { + if this.compressionCacheWriter != nil { + _ = this.compressionCacheWriter.Close() + } this.compressionCacheWriter = compressionCacheWriter var teeWriter = writers.NewTeeWriterCloser(this.writer, compressionCacheWriter) teeWriter.OnFail(func(err error) {