mirror of
				https://github.com/TeaOSLab/EdgeNode.git
				synced 2025-11-04 07:40:56 +08:00 
			
		
		
		
	缓存策略增加“允许读取不完整的Partial Content”选项
This commit is contained in:
		@@ -1004,6 +1004,11 @@ func (this *FileStorage) CanSendfile() bool {
 | 
				
			|||||||
	return this.options.EnableSendfile
 | 
						return this.options.EnableSendfile
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// Options 获取当前缓存存储的选项
 | 
				
			||||||
 | 
					func (this *FileStorage) Options() *serverconfigs.HTTPFileCacheStorage {
 | 
				
			||||||
 | 
						return this.options
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// 获取Key对应的文件路径
 | 
					// 获取Key对应的文件路径
 | 
				
			||||||
func (this *FileStorage) keyPath(key string) (hash string, path string, diskIsFull bool) {
 | 
					func (this *FileStorage) keyPath(key string) (hash string, path string, diskIsFull bool) {
 | 
				
			||||||
	hash = stringutil.Md5(key)
 | 
						hash = stringutil.Md5(key)
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -722,14 +722,20 @@ func (this *HTTPRequest) tryPartialReader(storage caches.StorageInterface, key s
 | 
				
			|||||||
		ranges[0][1] < 0 &&
 | 
							ranges[0][1] < 0 &&
 | 
				
			||||||
		!partialReader.IsCompleted() {
 | 
							!partialReader.IsCompleted() {
 | 
				
			||||||
		if partialReader.BodySize() > 0 {
 | 
							if partialReader.BodySize() > 0 {
 | 
				
			||||||
			var r = ranges[0]
 | 
								var options = this.ReqServer.HTTPCachePolicy.Options
 | 
				
			||||||
			r2, findOk := partialReader.Ranges().FindRangeAtPosition(r.Start())
 | 
								if options != nil {
 | 
				
			||||||
			if findOk && r2.Length() >= (256<<10) /* worth reading */ {
 | 
									fileStorage, isFileStorage := storage.(*caches.FileStorage)
 | 
				
			||||||
				isOk = true
 | 
									if isFileStorage && fileStorage.Options() != nil && fileStorage.Options().EnableIncompletePartialContent {
 | 
				
			||||||
				ranges[0] = [2]int64{r.Start(), partialReader.BodySize() - 1} // Content-Range: bytes 0-[CONTENT_LENGTH - 1]/CONTENT_LENGTH
 | 
										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))
 | 
											pReader.SetNextReader(NewHTTPRequestPartialReader(this, r2.End(), partialReader))
 | 
				
			||||||
				return pReader, ranges, r2.End() - 1 /* not include last byte */, true
 | 
											return pReader, ranges, r2.End() - 1 /* not include last byte */, true
 | 
				
			||||||
 | 
										}
 | 
				
			||||||
 | 
									}
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		return
 | 
							return
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user