diff --git a/internal/nodes/http_request_fastcgi.go b/internal/nodes/http_request_fastcgi.go index cd6ee15..fd70b33 100644 --- a/internal/nodes/http_request_fastcgi.go +++ b/internal/nodes/http_request_fastcgi.go @@ -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) diff --git a/internal/nodes/http_request_reverse_proxy.go b/internal/nodes/http_request_reverse_proxy.go index 7791858..5fce959 100644 --- a/internal/nodes/http_request_reverse_proxy.go +++ b/internal/nodes/http_request_reverse_proxy.go @@ -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) diff --git a/internal/nodes/http_request_root.go b/internal/nodes/http_request_root.go index 8440587..4ba7604 100644 --- a/internal/nodes/http_request_root.go +++ b/internal/nodes/http_request_root.go @@ -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() diff --git a/internal/nodes/http_request_url.go b/internal/nodes/http_request_url.go index 29e0fcc..78e16a4 100644 --- a/internal/nodes/http_request_url.go +++ b/internal/nodes/http_request_url.go @@ -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 { diff --git a/internal/nodes/http_writer.go b/internal/nodes/http_writer.go index 050fc41..0ca80a0 100644 --- a/internal/nodes/http_writer.go +++ b/internal/nodes/http_writer.go @@ -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 }