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

@@ -42,8 +42,25 @@ func (this *HTTPRequestPartialReader) Read(p []byte) (n int, err error) {
err = io.ErrUnexpectedEOF
return
}
this.resp = resp
// 对比Content-MD5
partialReader, ok := this.cacheReader.(*caches.PartialFileReader)
if ok {
if partialReader.Ranges().Version >= 2 && resp.Header.Get("Content-MD5") != partialReader.Ranges().ContentMD5 {
err = io.ErrUnexpectedEOF
var storage = this.req.writer.cacheStorage
if storage != nil {
_ = storage.Delete(this.req.cacheKey + caches.SuffixPartial)
}
return
}
}
// 准备写入
this.prepareCacheWriter()
}