@@ -24,14 +24,9 @@ var defaultTransport = sync.OnceValue(func() http.RoundTripper {
2424 }
2525})
2626
27- func DialContextWithTimeout (timeout time.Duration ) func (ctx context.Context , netw , addr string ) (net.Conn , error ) {
28- return func (ctx context.Context , netw , addr string ) (net.Conn , error ) {
29- d := net.Dialer {Timeout : timeout }
30- conn , err := d .DialContext (ctx , netw , addr )
31- if err != nil {
32- return nil , err
33- }
34- return conn , nil
27+ func DialContextWithTimeout (timeout time.Duration ) func (ctx context.Context , network , address string ) (net.Conn , error ) {
28+ return func (ctx context.Context , network , address string ) (net.Conn , error ) {
29+ return (& net.Dialer {Timeout : timeout }).DialContext (ctx , network , address )
3530 }
3631}
3732
@@ -47,7 +42,7 @@ func NewRequest(url, method string) *Request {
4742 },
4843 params : map [string ]string {},
4944
50- // from legacy httplib, caller's must pay more attention to it, it will cause annoying bugs when the response takes a long time
45+ // ATTENTION: from legacy httplib, callers must pay more attention to it, it will cause annoying bugs when the response takes a long time
5146 readWriteTimeout : 60 * time .Second ,
5247 }
5348}
@@ -68,7 +63,7 @@ func (r *Request) SetContext(ctx context.Context) *Request {
6863}
6964
7065// SetTransport sets the request transport, if not set, will use httplib's default transport with environment proxy support
71- // ATTENTION: the http.Transport has connection pool, so you should reuse it as much as possible, do not create a lot of transports
66+ // ATTENTION: the http.Transport has a connection pool, so it should be reused as much as possible, do not create a lot of transports
7267func (r * Request ) SetTransport (transport http.RoundTripper ) * Request {
7368 r .transport = transport
7469 return r
0 commit comments