From b1d0c8852e6271ba70c3ef0e7428fe71bb2f86d6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=98=E7=A5=A5=E8=B6=85?= Date: Sat, 18 Jun 2022 19:31:10 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A6=82=E6=9E=9C=E7=BC=93=E5=AD=98=E6=9D=A1?= =?UTF-8?q?=E4=BB=B6=E6=94=AF=E6=8C=81206=20Partial=20Content=EF=BC=8C?= =?UTF-8?q?=E5=88=99=E7=AC=AC=E4=B8=80=E6=AC=A1=E5=8A=A0=E8=BD=BD=E6=97=B6?= =?UTF-8?q?=E8=87=AA=E5=8A=A8=E5=B0=9D=E8=AF=95=E4=BB=8E=E5=88=86=E7=89=87?= =?UTF-8?q?=E7=BC=93=E5=AD=98=E4=B8=AD=E8=AF=BB=E5=8F=96=E5=86=85=E5=AE=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- internal/nodes/http_request_cache.go | 5 +++++ internal/nodes/http_writer.go | 5 +++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/internal/nodes/http_request_cache.go b/internal/nodes/http_request_cache.go index bc07ad2..7583682 100644 --- a/internal/nodes/http_request_cache.go +++ b/internal/nodes/http_request_cache.go @@ -236,6 +236,11 @@ func (this *HTTPRequest) doCacheRead(useStale bool) (shouldStop bool) { if reader == nil { reader, err = storage.OpenReader(key, useStale, false) if err != nil && this.cacheRef.AllowPartialContent { + // 尝试读取分片的缓存内容 + if len(rangeHeader) == 0 { + // 默认读取开头 + rangeHeader = "bytes=0-" + } pReader, ranges := this.tryPartialReader(storage, key, useStale, rangeHeader) if pReader != nil { isPartialCache = true diff --git a/internal/nodes/http_writer.go b/internal/nodes/http_writer.go index 1d0b72d..c91a9a3 100644 --- a/internal/nodes/http_writer.go +++ b/internal/nodes/http_writer.go @@ -312,9 +312,10 @@ func (this *HTTPWriter) PrepareCache(resp *http.Response, size int64) { if !caches.CanIgnoreErr(err) { remotelogs.Error("HTTP_WRITER", "write cache failed: "+err.Error()) + this.Header().Set("X-Cache", "BYPASS, write cache failed") + } else { + this.Header().Set("X-Cache", "BYPASS, "+err.Error()) } - - this.Header().Set("X-Cache", "BYPASS, too many requests") return } this.cacheWriter = cacheWriter