mirror of
https://github.com/TeaOSLab/EdgeNode.git
synced 2026-01-01 19:16:35 +08:00
优化Partial Content兼容性
This commit is contained in:
@@ -628,14 +628,14 @@ func (this *HTTPRequest) tryPartialReader(storage caches.StorageInterface, key s
|
||||
}()
|
||||
|
||||
// 检查范围
|
||||
const maxFirstSpan = 16 << 20 // TODO 可以在缓存策略中设置此值
|
||||
//const maxFirstSpan = 16 << 20 // TODO 可以在缓存策略中设置此值
|
||||
for index, r := range ranges {
|
||||
// 没有指定结束字节时,自动指定一个
|
||||
if r.Start() >= 0 && r.End() == -1 {
|
||||
// 没有指定结束位置时,自动指定一个
|
||||
/**if r.Start() >= 0 && r.End() == -1 {
|
||||
if partialReader.MaxLength() > r.Start()+maxFirstSpan {
|
||||
r[1] = r.Start() + maxFirstSpan
|
||||
}
|
||||
}
|
||||
}**/
|
||||
r1, ok := r.Convert(partialReader.MaxLength())
|
||||
if !ok {
|
||||
return nil, nil
|
||||
|
||||
@@ -303,7 +303,19 @@ func (this *HTTPWriter) PrepareCache(resp *http.Response, size int64) {
|
||||
if this.isPartial {
|
||||
cacheKey += caches.SuffixPartial
|
||||
}
|
||||
cacheWriter, err := storage.OpenWriter(cacheKey, expiresAt, this.StatusCode(), this.calculateHeaderLength(), size, cacheRef.MaxSizeBytes(), this.isPartial)
|
||||
|
||||
// 待写入尺寸
|
||||
var totalSize = size
|
||||
if totalSize < 0 && this.isPartial {
|
||||
var contentRange = resp.Header.Get("Content-Range")
|
||||
if len(contentRange) > 0 {
|
||||
_, partialTotalSize := httpRequestParseContentRangeHeader(contentRange)
|
||||
if partialTotalSize > 0 {
|
||||
totalSize = partialTotalSize
|
||||
}
|
||||
}
|
||||
}
|
||||
cacheWriter, err := storage.OpenWriter(cacheKey, expiresAt, this.StatusCode(), this.calculateHeaderLength(), totalSize, cacheRef.MaxSizeBytes(), this.isPartial)
|
||||
if err != nil {
|
||||
if err == caches.ErrEntityTooLarge && addStatusHeader {
|
||||
this.Header().Set("X-Cache", "BYPASS, entity too large")
|
||||
|
||||
Reference in New Issue
Block a user