mirror of
				https://github.com/TeaOSLab/EdgeNode.git
				synced 2025-11-04 07:40:56 +08:00 
			
		
		
		
	修复缓存状态码不生效的问题
This commit is contained in:
		@@ -189,7 +189,7 @@ func (this *HTTPRequest) doFastcgi() (shouldStop bool) {
 | 
			
		||||
	this.processResponseHeaders(resp.StatusCode)
 | 
			
		||||
 | 
			
		||||
	// 准备
 | 
			
		||||
	this.writer.Prepare(resp.ContentLength)
 | 
			
		||||
	this.writer.Prepare(resp.ContentLength, resp.StatusCode)
 | 
			
		||||
 | 
			
		||||
	// 设置响应代码
 | 
			
		||||
	this.writer.WriteHeader(resp.StatusCode)
 | 
			
		||||
 
 | 
			
		||||
@@ -226,7 +226,7 @@ func (this *HTTPRequest) doReverseProxy() {
 | 
			
		||||
	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)
 | 
			
		||||
 
 | 
			
		||||
@@ -296,7 +296,7 @@ func (this *HTTPRequest) doRoot() (isBreak bool) {
 | 
			
		||||
		this.cacheRef = nil // 不支持缓存
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	this.writer.Prepare(fileSize)
 | 
			
		||||
	this.writer.Prepare(fileSize, http.StatusOK)
 | 
			
		||||
 | 
			
		||||
	pool := this.bytePool(fileSize)
 | 
			
		||||
	buf := pool.Get()
 | 
			
		||||
 
 | 
			
		||||
@@ -50,7 +50,11 @@ func (this *HTTPRequest) doURL(method string, url string, host string, statusCod
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	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 {
 | 
			
		||||
 
 | 
			
		||||
@@ -9,6 +9,7 @@ import (
 | 
			
		||||
	"github.com/TeaOSLab/EdgeNode/internal/remotelogs"
 | 
			
		||||
	"github.com/TeaOSLab/EdgeNode/internal/utils"
 | 
			
		||||
	"github.com/iwind/TeaGo/lists"
 | 
			
		||||
	"github.com/iwind/TeaGo/logs"
 | 
			
		||||
	"net"
 | 
			
		||||
	"net/http"
 | 
			
		||||
	"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.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()) {
 | 
			
		||||
		return
 | 
			
		||||
	}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user