Partial Content从源站读取数据时验证本地缓存的Content-MD5是否一致

This commit is contained in:
刘祥超
2024-05-07 17:27:10 +08:00
parent 0b216090f1
commit 1144ca8a8b
7 changed files with 58 additions and 8 deletions

View File

@@ -403,6 +403,11 @@ func (this *HTTPWriter) PrepareCache(resp *http.Response, size int64) {
return
}
partialWriter.SetBodyLength(total)
var contentMD5 = this.rawWriter.Header().Get("Content-MD5")
if len(contentMD5) > 0 {
partialWriter.SetContentMD5(contentMD5)
}
}
var filterReader = readers.NewFilterReaderCloser(resp.Body)
this.cacheIsFinished = true
@@ -462,6 +467,11 @@ func (this *HTTPWriter) PrepareCache(resp *http.Response, size int64) {
// 写入total
if !writtenTotal && total > 0 {
partialWriter.SetBodyLength(total)
var contentMD5 = this.rawWriter.Header().Get("Content-MD5")
if len(contentMD5) > 0 {
partialWriter.SetContentMD5(contentMD5)
}
writtenTotal = true
}