mirror of
https://github.com/TeaOSLab/EdgeNode.git
synced 2025-11-19 04:10:30 +08:00
当缓存条件状态码为206时,自动支持区间缓存
This commit is contained in:
@@ -120,7 +120,7 @@ func (this *HTTPRequest) doCacheRead(useStale bool) (shouldStop bool) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
var method = this.Method()
|
var method = this.Method()
|
||||||
if method != http.MethodGet && method != http.MethodPost {
|
if method != http.MethodGet {
|
||||||
key += caches.SuffixMethod + method
|
key += caches.SuffixMethod + method
|
||||||
tags = append(tags, strings.ToLower(method))
|
tags = append(tags, strings.ToLower(method))
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -100,7 +100,8 @@ func (this *HTTPWriter) Prepare(resp *http.Response, size int64, status int, ena
|
|||||||
this.size = size
|
this.size = size
|
||||||
this.statusCode = status
|
this.statusCode = status
|
||||||
|
|
||||||
this.isPartial = status == http.StatusPartialContent
|
// 是否为区间请求
|
||||||
|
this.isPartial = status == http.StatusPartialContent && this.req.Method() != http.MethodHead
|
||||||
|
|
||||||
if resp != nil && resp.Body != nil {
|
if resp != nil && resp.Body != nil {
|
||||||
cacheReader, ok := resp.Body.(caches.Reader)
|
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"
|
this.req.varMapping["cache.status"] = "BYPASS"
|
||||||
if addStatusHeader {
|
if addStatusHeader {
|
||||||
this.Header().Set("X-Cache", "BYPASS, Status: "+types.String(this.StatusCode()))
|
this.Header().Set("X-Cache", "BYPASS, Status: "+types.String(this.StatusCode()))
|
||||||
|
|||||||
Reference in New Issue
Block a user