From 757d316a534a3d90266c557b87aae0750a32413e 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:37 +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 --- pkg/configutils/copy.go | 2 +- pkg/serverconfigs/http_cache_ref.go | 27 ++++++++++++++++++++++++++- 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/pkg/configutils/copy.go b/pkg/configutils/copy.go index 732565f..fcd284e 100644 --- a/pkg/configutils/copy.go +++ b/pkg/configutils/copy.go @@ -4,7 +4,7 @@ import ( "reflect" ) -// 拷贝同类型struct指针对象中的字段 +// CopyStructObject 拷贝同类型struct指针对象中的字段 func CopyStructObject(destPtr, sourcePtr interface{}) { value := reflect.ValueOf(destPtr) value2 := reflect.ValueOf(sourcePtr) diff --git a/pkg/serverconfigs/http_cache_ref.go b/pkg/serverconfigs/http_cache_ref.go index 1cc573d..dd58e5c 100644 --- a/pkg/serverconfigs/http_cache_ref.go +++ b/pkg/serverconfigs/http_cache_ref.go @@ -38,7 +38,8 @@ type HTTPCacheRef struct { maxSize int64 uppercaseSkipCacheControlValues []string - methodMap map[string]bool + methodMap map[string]bool + statusList []int } func (this *HTTPCacheRef) Init() error { @@ -82,6 +83,16 @@ func (this *HTTPCacheRef) Init() error { } } + // status + this.statusList = this.Status + if this.AllowPartialContent { + if !lists.ContainsInt(this.statusList, http.StatusPartialContent) { + this.statusList = append(this.statusList, http.StatusPartialContent) + } + } else if lists.ContainsInt(this.statusList, http.StatusPartialContent) { + this.AllowPartialContent = true + } + return nil } @@ -117,3 +128,17 @@ func (this *HTTPCacheRef) MatchRequest(req *http.Request) bool { return true } + +// MatchStatus 检查是否包含某个状态码 +func (this *HTTPCacheRef) MatchStatus(statusCode int) bool { + if len(this.statusList) == 0 { + return true + } + + for _, status := range this.statusList { + if status == statusCode { + return true + } + } + return false +}