diff --git a/internal/caches/writer_partial_file.go b/internal/caches/writer_partial_file.go index fbdfe6e..da7b4fb 100644 --- a/internal/caches/writer_partial_file.go +++ b/internal/caches/writer_partial_file.go @@ -294,6 +294,10 @@ func (this *PartialFileWriter) IsNew() bool { return this.isNew && len(this.ranges.Ranges) == 0 } +func (this *PartialFileWriter) Ranges() *PartialRanges { + return this.ranges +} + func (this *PartialFileWriter) remove() { _ = fsutils.Remove(this.rawWriter.Name()) diff --git a/internal/nodes/http_writer.go b/internal/nodes/http_writer.go index df790e0..f8822fa 100644 --- a/internal/nodes/http_writer.go +++ b/internal/nodes/http_writer.go @@ -355,6 +355,19 @@ func (this *HTTPWriter) PrepareCache(resp *http.Response, size int64) { } this.cacheWriter = cacheWriter + // 对比Content-MD5 + { + partialWriter, ok := cacheWriter.(*caches.PartialFileWriter) + if ok { + 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() }