diff --git a/curlx.go b/curlx.go index e95e1a3..84c0d96 100644 --- a/curlx.go +++ b/curlx.go @@ -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...) diff --git a/curlx_test.go b/curlx_test.go index 40e56e0..352d73a 100644 --- a/curlx_test.go +++ b/curlx_test.go @@ -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) +} diff --git a/params.go b/params.go index 80cced1..6075dee 100644 --- a/params.go +++ b/params.go @@ -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 */