Skip to content

Commit a0044d6

Browse files
committed
fine tune
1 parent 901c3a1 commit a0044d6

File tree

2 files changed

+7
-12
lines changed

2 files changed

+7
-12
lines changed

modules/httplib/request.go

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -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
7267
func (r *Request) SetTransport(transport http.RoundTripper) *Request {
7368
r.transport = transport
7469
return r

modules/private/internal.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,15 +42,15 @@ func dialContextInternalAPI(ctx context.Context, network, address string) (conn
4242
conn, err = d.DialContext(ctx, network, address)
4343
}
4444
if err != nil {
45-
return conn, err
45+
return nil, err
4646
}
4747
if setting.LocalUseProxyProtocol {
4848
if err = proxyprotocol.WriteLocalHeader(conn); err != nil {
4949
_ = conn.Close()
5050
return nil, err
5151
}
5252
}
53-
return conn, err
53+
return conn, nil
5454
}
5555

5656
var internalAPITransport = sync.OnceValue(func() http.RoundTripper {

0 commit comments

Comments
 (0)