当缓存条件状态码为206时,自动支持区间缓存

This commit is contained in:
刘祥超
2022-03-04 17:00:37 +08:00
parent 1d681d5029
commit 757d316a53
2 changed files with 27 additions and 2 deletions

View File

@@ -4,7 +4,7 @@ import (
"reflect"
)
// 拷贝同类型struct指针对象中的字段
// CopyStructObject 拷贝同类型struct指针对象中的字段
func CopyStructObject(destPtr, sourcePtr interface{}) {
value := reflect.ValueOf(destPtr)
value2 := reflect.ValueOf(sourcePtr)

View File

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