缓存策略增加“允许读取不完整的Partial Content”选项

This commit is contained in:
GoEdgeLab
2024-05-07 20:06:06 +08:00
parent bbc892ad4b
commit c463b2a053
2 changed files with 18 additions and 7 deletions

View File

@@ -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)

View File

@@ -722,6 +722,10 @@ func (this *HTTPRequest) tryPartialReader(storage caches.StorageInterface, key s
ranges[0][1] < 0 &&
!partialReader.IsCompleted() {
if partialReader.BodySize() > 0 {
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 */ {
@@ -732,6 +736,8 @@ func (this *HTTPRequest) tryPartialReader(storage caches.StorageInterface, key s
return pReader, ranges, r2.End() - 1 /* not include last byte */, true
}
}
}
}
return
}