修复缓存状态码不生效的问题

This commit is contained in:
刘祥超
2021-05-23 14:29:56 +08:00
parent 63e3b7ac2f
commit b2f18c22ee
5 changed files with 13 additions and 5 deletions

View File

@@ -189,7 +189,7 @@ func (this *HTTPRequest) doFastcgi() (shouldStop bool) {
this.processResponseHeaders(resp.StatusCode) this.processResponseHeaders(resp.StatusCode)
// 准备 // 准备
this.writer.Prepare(resp.ContentLength) this.writer.Prepare(resp.ContentLength, resp.StatusCode)
// 设置响应代码 // 设置响应代码
this.writer.WriteHeader(resp.StatusCode) this.writer.WriteHeader(resp.StatusCode)

View File

@@ -226,7 +226,7 @@ func (this *HTTPRequest) doReverseProxy() {
shouldAutoFlush := this.reverseProxy.AutoFlush || this.RawReq.Header.Get("Accept") == "text/event-stream" shouldAutoFlush := this.reverseProxy.AutoFlush || this.RawReq.Header.Get("Accept") == "text/event-stream"
// 准备 // 准备
this.writer.Prepare(resp.ContentLength) this.writer.Prepare(resp.ContentLength, resp.StatusCode)
// 设置响应代码 // 设置响应代码
this.writer.WriteHeader(resp.StatusCode) this.writer.WriteHeader(resp.StatusCode)

View File

@@ -296,7 +296,7 @@ func (this *HTTPRequest) doRoot() (isBreak bool) {
this.cacheRef = nil // 不支持缓存 this.cacheRef = nil // 不支持缓存
} }
this.writer.Prepare(fileSize) this.writer.Prepare(fileSize, http.StatusOK)
pool := this.bytePool(fileSize) pool := this.bytePool(fileSize)
buf := pool.Get() buf := pool.Get()

View File

@@ -50,7 +50,11 @@ func (this *HTTPRequest) doURL(method string, url string, host string, statusCod
} }
this.writer.AddHeaders(resp.Header) this.writer.AddHeaders(resp.Header)
this.writer.Prepare(resp.ContentLength) if statusCode <= 0 {
this.writer.Prepare(resp.ContentLength, resp.StatusCode)
} else {
this.writer.Prepare(resp.ContentLength, statusCode)
}
// 设置响应代码 // 设置响应代码
if statusCode <= 0 { if statusCode <= 0 {

View File

@@ -9,6 +9,7 @@ import (
"github.com/TeaOSLab/EdgeNode/internal/remotelogs" "github.com/TeaOSLab/EdgeNode/internal/remotelogs"
"github.com/TeaOSLab/EdgeNode/internal/utils" "github.com/TeaOSLab/EdgeNode/internal/utils"
"github.com/iwind/TeaGo/lists" "github.com/iwind/TeaGo/lists"
"github.com/iwind/TeaGo/logs"
"net" "net"
"net/http" "net/http"
"strings" "strings"
@@ -64,7 +65,9 @@ func (this *HTTPWriter) Gzip(config *serverconfigs.HTTPGzipConfig) {
} }
// 准备输出 // 准备输出
func (this *HTTPWriter) Prepare(size int64) { func (this *HTTPWriter) Prepare(size int64, status int) {
this.statusCode = status
this.prepareGzip(size) this.prepareGzip(size)
this.prepareCache(size) this.prepareCache(size)
} }
@@ -333,6 +336,7 @@ func (this *HTTPWriter) prepareCache(size int64) {
} }
// 检查状态 // 检查状态
logs.Println("status:", cacheRef.Status, this.StatusCode()) // TODO
if len(cacheRef.Status) > 0 && !lists.ContainsInt(cacheRef.Status, this.StatusCode()) { if len(cacheRef.Status) > 0 && !lists.ContainsInt(cacheRef.Status, this.StatusCode()) {
return return
} }