From 16c123c4006dc3f7ddacecb5cf71aa218822ca94 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=98=E7=A5=A5=E8=B6=85?= Date: Fri, 4 Mar 2022 17:00:48 +0800 Subject: [PATCH] =?UTF-8?q?=E5=BD=93=E7=BC=93=E5=AD=98=E6=9D=A1=E4=BB=B6?= =?UTF-8?q?=E7=8A=B6=E6=80=81=E7=A0=81=E4=B8=BA206=E6=97=B6=EF=BC=8C?= =?UTF-8?q?=E8=87=AA=E5=8A=A8=E6=94=AF=E6=8C=81=E5=8C=BA=E9=97=B4=E7=BC=93?= =?UTF-8?q?=E5=AD=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- internal/nodes/http_request_cache.go | 2 +- internal/nodes/http_writer.go | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/internal/nodes/http_request_cache.go b/internal/nodes/http_request_cache.go index c070ed9..8e2ffa4 100644 --- a/internal/nodes/http_request_cache.go +++ b/internal/nodes/http_request_cache.go @@ -120,7 +120,7 @@ func (this *HTTPRequest) doCacheRead(useStale bool) (shouldStop bool) { return } var method = this.Method() - if method != http.MethodGet && method != http.MethodPost { + if method != http.MethodGet { key += caches.SuffixMethod + method tags = append(tags, strings.ToLower(method)) } diff --git a/internal/nodes/http_writer.go b/internal/nodes/http_writer.go index 19bdc82..007fe68 100644 --- a/internal/nodes/http_writer.go +++ b/internal/nodes/http_writer.go @@ -100,7 +100,8 @@ func (this *HTTPWriter) Prepare(resp *http.Response, size int64, status int, ena this.size = size this.statusCode = status - this.isPartial = status == http.StatusPartialContent + // 是否为区间请求 + this.isPartial = status == http.StatusPartialContent && this.req.Method() != http.MethodHead if resp != nil && resp.Body != nil { cacheReader, ok := resp.Body.(caches.Reader) @@ -184,7 +185,7 @@ func (this *HTTPWriter) PrepareCache(resp *http.Response, size int64) { } // 检查状态 - if !this.isPartial && len(cacheRef.Status) > 0 && !lists.ContainsInt(cacheRef.Status, this.StatusCode()) { + if !cacheRef.MatchStatus(this.StatusCode()) { this.req.varMapping["cache.status"] = "BYPASS" if addStatusHeader { this.Header().Set("X-Cache", "BYPASS, Status: "+types.String(this.StatusCode()))