Merge remote-tracking branch 'github/master' into dev

This commit is contained in:
Yun
2025-09-13 17:50:24 +08:00
3 changed files with 22 additions and 2 deletions
+6 -2
View File
@@ -79,6 +79,10 @@ func (c *Curlx) WithProxySocks5(address string) error {
baseDialer := &net.Dialer{
// Timeout: 180 * time.Second,
// KeepAlive: 180 * time.Second,
Resolver: &net.Resolver{
PreferGo: true,
Dial: c.transport.DialContext,
},
}
dialSocksProxy, err := proxy.SOCKS5("tcp", address, nil, baseDialer)
if err != nil {
@@ -94,7 +98,7 @@ func (c *Curlx) WithProxySocks5(address string) error {
}
/**
* 使用HTTP代理
* 使用HTTP/HTTPS代理
* @param proxyAddr "https://proxyserver:port"
*/
func (c *Curlx) WithProxyHttp(proxyAddr string) error {
@@ -311,7 +315,7 @@ func (c *Curlx) SendStream(ctx context.Context, ps ...Param) (<-chan string, err
go func() {
defer close(data)
ctx, cancel := context.WithTimeout(context.Background(), time.Minute*30)
ctx, cancel := context.WithTimeout(context.Background(), c.opts.TimeOut)
defer cancel()
_, response, err := c.SendExec(ctx, ps...)
+7
View File
@@ -48,3 +48,10 @@ func TestForm(t *testing.T) {
resp, code, err := NewCurlx().Send(context.Background(), SetParamsAll(p))
fmt.Println(resp, code, err)
}
func TestProxy(t *testing.T) {
c := NewCurlx()
c.WithProxySocks5("127.0.0.1:1080")
res, code, err := c.Send(context.Background(), SetParamsUrl("https://www.google.com"),SetParamsMethod(MethodGet))
t.Log(string(res), code, err)
}
+9
View File
@@ -97,6 +97,15 @@ func SetParamsHeaders(h map[string]interface{}) Param {
}
}
/**
* 设置请求头
*/
func SetParamsHeader(key, value string) Param {
return func(param *ClientParams) {
param.Headers[key] = value
}
}
/**
* 设置UserAgent
*/