diff --git a/internal/caches/storage_file.go b/internal/caches/storage_file.go index a03f225..daf8c41 100644 --- a/internal/caches/storage_file.go +++ b/internal/caches/storage_file.go @@ -1004,6 +1004,11 @@ func (this *FileStorage) CanSendfile() bool { return this.options.EnableSendfile } +// Options 获取当前缓存存储的选项 +func (this *FileStorage) Options() *serverconfigs.HTTPFileCacheStorage { + return this.options +} + // 获取Key对应的文件路径 func (this *FileStorage) keyPath(key string) (hash string, path string, diskIsFull bool) { hash = stringutil.Md5(key) diff --git a/internal/nodes/http_request_cache.go b/internal/nodes/http_request_cache.go index 4f8016c..6a16dd3 100644 --- a/internal/nodes/http_request_cache.go +++ b/internal/nodes/http_request_cache.go @@ -722,14 +722,20 @@ func (this *HTTPRequest) tryPartialReader(storage caches.StorageInterface, key s ranges[0][1] < 0 && !partialReader.IsCompleted() { if partialReader.BodySize() > 0 { - var r = ranges[0] - r2, findOk := partialReader.Ranges().FindRangeAtPosition(r.Start()) - if findOk && r2.Length() >= (256<<10) /* worth reading */ { - isOk = true - ranges[0] = [2]int64{r.Start(), partialReader.BodySize() - 1} // Content-Range: bytes 0-[CONTENT_LENGTH - 1]/CONTENT_LENGTH + var options = this.ReqServer.HTTPCachePolicy.Options + if options != nil { + fileStorage, isFileStorage := storage.(*caches.FileStorage) + if isFileStorage && fileStorage.Options() != nil && fileStorage.Options().EnableIncompletePartialContent { + var r = ranges[0] + r2, findOk := partialReader.Ranges().FindRangeAtPosition(r.Start()) + if findOk && r2.Length() >= (256<<10) /* worth reading */ { + isOk = true + ranges[0] = [2]int64{r.Start(), partialReader.BodySize() - 1} // Content-Range: bytes 0-[CONTENT_LENGTH - 1]/CONTENT_LENGTH - pReader.SetNextReader(NewHTTPRequestPartialReader(this, r2.End(), partialReader)) - return pReader, ranges, r2.End() - 1 /* not include last byte */, true + pReader.SetNextReader(NewHTTPRequestPartialReader(this, r2.End(), partialReader)) + return pReader, ranges, r2.End() - 1 /* not include last byte */, true + } + } } } return