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 +}