mirror of
https://github.com/TeaOSLab/EdgeNode.git
synced 2025-11-06 18:10:26 +08:00
修复源站重试时可能产生的file is writing错误
This commit is contained in:
@@ -104,6 +104,18 @@ func NewHTTPWriter(req *HTTPRequest, httpResponseWriter http.ResponseWriter) *HT
|
|||||||
|
|
||||||
// Prepare 准备输出
|
// Prepare 准备输出
|
||||||
func (this *HTTPWriter) Prepare(resp *http.Response, size int64, status int, enableCache bool) (delayHeaders bool) {
|
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.size = size
|
||||||
this.statusCode = status
|
this.statusCode = status
|
||||||
|
|
||||||
@@ -334,6 +346,9 @@ func (this *HTTPWriter) PrepareCache(resp *http.Response, size int64) {
|
|||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
if this.cacheWriter != nil {
|
||||||
|
_ = this.cacheWriter.Discard()
|
||||||
|
}
|
||||||
this.cacheWriter = cacheWriter
|
this.cacheWriter = cacheWriter
|
||||||
|
|
||||||
if this.isPartial {
|
if this.isPartial {
|
||||||
@@ -696,6 +711,9 @@ func (this *HTTPWriter) PrepareCompression(resp *http.Response, size int64) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if compressionCacheWriter != nil {
|
if compressionCacheWriter != nil {
|
||||||
|
if this.compressionCacheWriter != nil {
|
||||||
|
_ = this.compressionCacheWriter.Close()
|
||||||
|
}
|
||||||
this.compressionCacheWriter = compressionCacheWriter
|
this.compressionCacheWriter = compressionCacheWriter
|
||||||
var teeWriter = writers.NewTeeWriterCloser(this.writer, compressionCacheWriter)
|
var teeWriter = writers.NewTeeWriterCloser(this.writer, compressionCacheWriter)
|
||||||
teeWriter.OnFail(func(err error) {
|
teeWriter.OnFail(func(err error) {
|
||||||
|
|||||||
Reference in New Issue
Block a user