mirror of
				https://github.com/TeaOSLab/EdgeNode.git
				synced 2025-11-04 07:40:56 +08:00 
			
		
		
		
	特殊页面中的URL抓取的内容也支持请求变量
This commit is contained in:
		@@ -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
 | 
			
		||||
 
 | 
			
		||||
@@ -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
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -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
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -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 {
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user