mirror of
https://github.com/TeaOSLab/EdgeNode.git
synced 2025-11-05 01:20:26 +08:00
Partial Content新创建时不对比Content-MD5
This commit is contained in:
@@ -355,23 +355,28 @@ func (this *HTTPWriter) PrepareCache(resp *http.Response, size int64) {
|
|||||||
}
|
}
|
||||||
this.cacheWriter = cacheWriter
|
this.cacheWriter = cacheWriter
|
||||||
|
|
||||||
// 对比Content-MD5
|
if this.isPartial {
|
||||||
{
|
|
||||||
partialWriter, ok := cacheWriter.(*caches.PartialFileWriter)
|
partialWriter, ok := cacheWriter.(*caches.PartialFileWriter)
|
||||||
if ok {
|
if ok {
|
||||||
if partialWriter.Ranges().Version >= 2 && partialWriter.Ranges().ContentMD5 != this.Header().Get("Content-MD5") {
|
// 判断是否新创建的缓存文件
|
||||||
_ = this.cacheWriter.Discard()
|
this.partialFileIsNew = partialWriter.IsNew()
|
||||||
this.cacheWriter = nil
|
|
||||||
return
|
if this.partialFileIsNew {
|
||||||
|
var contentMD5 = this.rawWriter.Header().Get("Content-MD5")
|
||||||
|
if len(contentMD5) > 0 {
|
||||||
|
partialWriter.SetContentMD5(contentMD5)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// 对比Content-MD5
|
||||||
|
if partialWriter.Ranges().Version >= 2 && partialWriter.Ranges().ContentMD5 != this.Header().Get("Content-MD5") {
|
||||||
|
_ = this.cacheWriter.Discard()
|
||||||
|
this.cacheWriter = nil
|
||||||
|
return
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 判断是否新创建的缓存文件
|
|
||||||
if this.isPartial {
|
|
||||||
this.partialFileIsNew = cacheWriter.(*caches.PartialFileWriter).IsNew()
|
|
||||||
}
|
|
||||||
|
|
||||||
// 写入Header
|
// 写入Header
|
||||||
var headerBuf = utils.SharedBufferPool.Get()
|
var headerBuf = utils.SharedBufferPool.Get()
|
||||||
for k, v := range this.Header() {
|
for k, v := range this.Header() {
|
||||||
@@ -416,11 +421,6 @@ func (this *HTTPWriter) PrepareCache(resp *http.Response, size int64) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
partialWriter.SetBodyLength(total)
|
partialWriter.SetBodyLength(total)
|
||||||
|
|
||||||
var contentMD5 = this.rawWriter.Header().Get("Content-MD5")
|
|
||||||
if len(contentMD5) > 0 {
|
|
||||||
partialWriter.SetContentMD5(contentMD5)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
var filterReader = readers.NewFilterReaderCloser(resp.Body)
|
var filterReader = readers.NewFilterReaderCloser(resp.Body)
|
||||||
this.cacheIsFinished = true
|
this.cacheIsFinished = true
|
||||||
@@ -480,11 +480,6 @@ func (this *HTTPWriter) PrepareCache(resp *http.Response, size int64) {
|
|||||||
// 写入total
|
// 写入total
|
||||||
if !writtenTotal && total > 0 {
|
if !writtenTotal && total > 0 {
|
||||||
partialWriter.SetBodyLength(total)
|
partialWriter.SetBodyLength(total)
|
||||||
var contentMD5 = this.rawWriter.Header().Get("Content-MD5")
|
|
||||||
if len(contentMD5) > 0 {
|
|
||||||
partialWriter.SetContentMD5(contentMD5)
|
|
||||||
}
|
|
||||||
|
|
||||||
writtenTotal = true
|
writtenTotal = true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user