Compare commits

..
Author SHA1 Message Date
lan-yonghui ba415543fa fix: upgrade x/net HTML parser 2026-11-08 14:30:17 +08:00
8 changed files with 23 additions and 89 deletions
+1 -1
View File
@@ -56,7 +56,7 @@ require (
github.com/upyun/go-sdk v2.1.0+incompatible
go.mongodb.org/mongo-driver/v2 v2.9.2
golang.org/x/crypto v0.58.0
golang.org/x/net v0.60.0
golang.org/x/net v0.62.0
golang.org/x/sync v0.24.0
golang.org/x/sys v0.49.0
golang.org/x/text v0.43.0
+2
View File
@@ -1084,6 +1084,8 @@ golang.org/x/net v0.58.0 h1:ynWG7rqYi4ccpTEuPZ2QGWHktVEM9DMCj9yzDE0Q7To=
golang.org/x/net v0.58.0/go.mod h1:YwCddHnFlT7eLQqVprV19OnhLGtc5xOKgE0RyqgfWAU=
golang.org/x/net v0.60.0 h1:79p50tfZlm0J9YfoDsSi639qSXNGVwEzOPLCxM2FsYU=
golang.org/x/net v0.60.0/go.mod h1:2DA/G1UfVbCpQPeWTmMPGY7Cs2PkBkwu743bVX5PIVg=
golang.org/x/net v0.62.0 h1:18ELalfM5+XNRwzM2nYqXsZQ9ByS1uhj2O/U7+5jqRY=
golang.org/x/net v0.62.0/go.mod h1:WgDCOTH8iwtB66T4/GfI94AHo/hhdb7Hah9NDseQfiI=
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
-39
View File
@@ -1,39 +0,0 @@
package req_helper
import (
"crypto/tls"
"errors"
"net/http"
"time"
)
func newExternalHTTPClient(transport *http.Transport, timeout time.Duration) *http.Client {
if transport == nil {
transport = http.DefaultTransport.(*http.Transport)
}
verified := transport.Clone()
if verified.TLSClientConfig == nil {
verified.TLSClientConfig = &tls.Config{}
} else {
verified.TLSClientConfig = verified.TLSClientConfig.Clone()
}
verified.TLSClientConfig.InsecureSkipVerify = false
verified.TLSClientConfig.ServerName = ""
verified.DialTLS = nil
verified.DialTLSContext = nil
return &http.Client{
Timeout: timeout,
Transport: verified,
CheckRedirect: checkExternalRedirect,
}
}
func checkExternalRedirect(req *http.Request, via []*http.Request) error {
if len(via) >= 10 {
return errors.New("stopped after 10 redirects")
}
if len(via) > 0 && via[len(via)-1].URL.Scheme == "https" && req.URL.Scheme != "https" {
return errors.New("refusing HTTPS redirect to an insecure scheme")
}
return nil
}
+9 -6
View File
@@ -2,6 +2,7 @@ package req_helper
import (
"context"
"crypto/tls"
"errors"
"io"
"net"
@@ -20,7 +21,10 @@ import (
)
func HandleGet(url string) (*http.Response, error) {
client := newExternalHTTPClient(loadRequestTransport(), time.Second*300)
client := &http.Client{
Timeout: time.Second * 300,
}
client.Transport = loadRequestTransport()
defer client.CloseIdleConnections()
req, err := http.NewRequestWithContext(context.Background(), "GET", url, nil)
@@ -49,9 +53,8 @@ func HandleGet(url string) (*http.Response, error) {
func HandleRequest(url, method string, timeout int) (int, []byte, error) {
transport := xpack.MultiNodeProvider.LoadRequestTransport()
client := newExternalHTTPClient(transport, time.Duration(timeout)*time.Second)
defer client.CloseIdleConnections()
return HandleRequestWithClient(client, url, method, timeout)
client := http.Client{Timeout: time.Duration(timeout) * time.Second, Transport: transport}
return HandleRequestWithClient(&client, url, method, timeout)
}
func HandleRequestWithClient(client *http.Client, url, method string, timeout int) (int, []byte, error) {
@@ -133,8 +136,7 @@ func RequestFile(url, method string, timeout int) (io.ReadCloser, context.Cancel
}
}()
transport := xpack.MultiNodeProvider.LoadRequestTransport()
client := newExternalHTTPClient(transport, time.Duration(timeout)*time.Second)
defer client.CloseIdleConnections()
client := http.Client{Timeout: time.Duration(timeout) * time.Second, Transport: transport}
ctx, cancel := context.WithTimeout(context.Background(), time.Duration(timeout)*time.Second)
request, err := http.NewRequestWithContext(ctx, method, url, nil)
if err != nil {
@@ -154,6 +156,7 @@ func RequestFile(url, method string, timeout int) (io.ReadCloser, context.Cancel
func loadRequestTransport() *http.Transport {
return &http.Transport{
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
DialContext: (&net.Dialer{
Timeout: 60 * time.Second,
KeepAlive: 60 * time.Second,
+1 -1
View File
@@ -44,7 +44,7 @@ require (
github.com/xlzd/gotp v0.1.0
golang.org/x/crypto v0.58.0
golang.org/x/image v0.45.0
golang.org/x/net v0.60.0
golang.org/x/net v0.62.0
golang.org/x/oauth2 v0.36.0
golang.org/x/sys v0.49.0
golang.org/x/term v0.47.0
+2
View File
@@ -339,6 +339,8 @@ golang.org/x/net v0.58.0 h1:ynWG7rqYi4ccpTEuPZ2QGWHktVEM9DMCj9yzDE0Q7To=
golang.org/x/net v0.58.0/go.mod h1:YwCddHnFlT7eLQqVprV19OnhLGtc5xOKgE0RyqgfWAU=
golang.org/x/net v0.60.0 h1:79p50tfZlm0J9YfoDsSi639qSXNGVwEzOPLCxM2FsYU=
golang.org/x/net v0.60.0/go.mod h1:2DA/G1UfVbCpQPeWTmMPGY7Cs2PkBkwu743bVX5PIVg=
golang.org/x/net v0.62.0 h1:18ELalfM5+XNRwzM2nYqXsZQ9ByS1uhj2O/U7+5jqRY=
golang.org/x/net v0.62.0/go.mod h1:WgDCOTH8iwtB66T4/GfI94AHo/hhdb7Hah9NDseQfiI=
golang.org/x/oauth2 v0.36.0 h1:peZ/1z27fi9hUOFCAZaHyrpWG5lwe0RJEEEeH0ThlIs=
golang.org/x/oauth2 v0.36.0/go.mod h1:YDBUJMTkDnJS+A4BP4eZBjCqtokkg1hODuPjwiGPO7Q=
golang.org/x/sync v0.22.0 h1:SZjpbeLmrCk4xhRSZFNZW5gFUeCeFgjekvI/+gfScek=
-39
View File
@@ -1,39 +0,0 @@
package req_helper
import (
"crypto/tls"
"errors"
"net/http"
"time"
)
func newExternalHTTPClient(transport *http.Transport, timeout time.Duration) *http.Client {
if transport == nil {
transport = http.DefaultTransport.(*http.Transport)
}
verified := transport.Clone()
if verified.TLSClientConfig == nil {
verified.TLSClientConfig = &tls.Config{}
} else {
verified.TLSClientConfig = verified.TLSClientConfig.Clone()
}
verified.TLSClientConfig.InsecureSkipVerify = false
verified.TLSClientConfig.ServerName = ""
verified.DialTLS = nil
verified.DialTLSContext = nil
return &http.Client{
Timeout: timeout,
Transport: verified,
CheckRedirect: checkExternalRedirect,
}
}
func checkExternalRedirect(req *http.Request, via []*http.Request) error {
if len(via) >= 10 {
return errors.New("stopped after 10 redirects")
}
if len(via) > 0 && via[len(via)-1].URL.Scheme == "https" && req.URL.Scheme != "https" {
return errors.New("refusing HTTPS redirect to an insecure scheme")
}
return nil
}
+8 -3
View File
@@ -2,6 +2,7 @@ package req_helper
import (
"context"
"crypto/tls"
"errors"
"io"
"net"
@@ -16,6 +17,7 @@ import (
func HandleRequest(url, method string, timeout int) (int, []byte, error) {
transport := &http.Transport{
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
DialContext: (&net.Dialer{
Timeout: 60 * time.Second,
KeepAlive: 60 * time.Second,
@@ -40,8 +42,7 @@ func handleRequestWithTransport(url, method string, transport *http.Transport, t
}
}()
client := newExternalHTTPClient(transport, time.Duration(timeout)*time.Second)
defer client.CloseIdleConnections()
client := http.Client{Timeout: time.Duration(timeout) * time.Second, Transport: transport}
ctx, cancel := context.WithTimeout(context.Background(), time.Duration(timeout)*time.Second)
defer cancel()
request, err := http.NewRequestWithContext(ctx, method, url, nil)
@@ -64,6 +65,7 @@ func handleRequestWithTransport(url, method string, transport *http.Transport, t
func HandleGet(url string) (*http.Response, error) {
transport := &http.Transport{
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
DialContext: (&net.Dialer{
Timeout: 60 * time.Second,
KeepAlive: 60 * time.Second,
@@ -81,7 +83,10 @@ func HandleGetWithProxy(url string) (*http.Response, error) {
}
func handleGetWithTransport(url string, transport *http.Transport) (*http.Response, error) {
client := newExternalHTTPClient(transport, time.Second*300)
client := &http.Client{
Timeout: time.Second * 300,
}
client.Transport = transport
defer client.CloseIdleConnections()
req, err := http.NewRequestWithContext(context.Background(), "GET", url, nil)