mirror of
https://github.com/TeaOSLab/EdgeNode.git
synced 2025-11-03 23:20:25 +08:00
特殊页面中的URL抓取的内容也支持请求变量
This commit is contained in:
@@ -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