diff --git a/internal/nodes/http_request_page.go b/internal/nodes/http_request_page.go index aaa5d69..96eb255 100644 --- a/internal/nodes/http_request_page.go +++ b/internal/nodes/http_request_page.go @@ -21,7 +21,7 @@ func (this *HTTPRequest) doPage(status int) (shouldStop bool) { for _, page := range this.web.Pages { if page.Match(status) { if urlPrefixRegexp.MatchString(page.URL) { - this.doURL(http.MethodGet, page.URL, "", page.NewStatus) + this.doURL(http.MethodGet, page.URL, "", page.NewStatus, true) return true } else { file := Tea.Root + Tea.DS + page.URL diff --git a/internal/nodes/http_request_rewrite.go b/internal/nodes/http_request_rewrite.go index c4c0997..bc0f777 100644 --- a/internal/nodes/http_request_rewrite.go +++ b/internal/nodes/http_request_rewrite.go @@ -19,7 +19,7 @@ func (this *HTTPRequest) doRewrite() (shouldShop bool) { if len(this.rewriteRule.ProxyHost) > 0 { host = this.rewriteRule.ProxyHost } - this.doURL(this.RawReq.Method, this.rewriteReplace, host, 0) + this.doURL(this.RawReq.Method, this.rewriteReplace, host, 0, false) return true } diff --git a/internal/nodes/http_request_shutdown.go b/internal/nodes/http_request_shutdown.go index 8c41f27..c019b18 100644 --- a/internal/nodes/http_request_shutdown.go +++ b/internal/nodes/http_request_shutdown.go @@ -17,7 +17,7 @@ func (this *HTTPRequest) doShutdown() { } if urlPrefixRegexp.MatchString(shutdown.URL) { // URL - this.doURL(http.MethodGet, shutdown.URL, "", shutdown.Status) + this.doURL(http.MethodGet, shutdown.URL, "", shutdown.Status, true) return } diff --git a/internal/nodes/http_request_url.go b/internal/nodes/http_request_url.go index 10b6bdc..9684ca6 100644 --- a/internal/nodes/http_request_url.go +++ b/internal/nodes/http_request_url.go @@ -1,7 +1,6 @@ package nodes import ( - "errors" "github.com/TeaOSLab/EdgeNode/internal/remotelogs" "github.com/TeaOSLab/EdgeNode/internal/utils" "github.com/iwind/TeaGo/logs" @@ -11,7 +10,7 @@ import ( ) // 请求某个URL -func (this *HTTPRequest) doURL(method string, url string, host string, statusCode int) { +func (this *HTTPRequest) doURL(method string, url string, host string, statusCode int, supportVariables bool) { req, err := http.NewRequest(method, url, this.RawReq.Body) if err != nil { logs.Error(err) @@ -35,7 +34,7 @@ func (this *HTTPRequest) doURL(method string, url string, host string, statusCod var client = utils.SharedHttpClient(60 * time.Second) resp, err := client.Do(req) if err != nil { - logs.Error(errors.New(req.URL.String() + ": " + err.Error())) + remotelogs.Error("HTTP_REQUEST_URL", req.URL.String()+": "+err.Error()) this.write50x(err, http.StatusInternalServerError) return } @@ -50,6 +49,9 @@ func (this *HTTPRequest) doURL(method string, url string, host string, statusCod this.processResponseHeaders(statusCode) } + if supportVariables { + resp.Header.Del("Content-Length") + } this.writer.AddHeaders(resp.Header) if statusCode <= 0 { this.writer.Prepare(resp.ContentLength, resp.StatusCode) @@ -67,7 +69,13 @@ func (this *HTTPRequest) doURL(method string, url string, host string, statusCod // 输出内容 pool := this.bytePool(resp.ContentLength) buf := pool.Get() - _, err = io.CopyBuffer(this.writer, resp.Body, buf) + if supportVariables { + _, err = utils.CopyWithFilter(this.writer, resp.Body, buf, func(p []byte) []byte { + return []byte(this.Format(string(p))) + }) + } else { + _, err = io.CopyBuffer(this.writer, resp.Body, buf) + } pool.Put(buf) if err != nil {