-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhttp.go
40 lines (36 loc) · 1.19 KB
/
http.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package netx
import (
"context"
"net"
"net/http"
"time"
"github.com/simia-tech/netx/value"
)
// NewHTTPTransport returns a new transport instance for a http client. The instance will use
// netx.Dial to establish a connection.
func NewHTTPTransport(network string, options ...value.Option) *http.Transport {
return &http.Transport{
Proxy: http.ProxyFromEnvironment,
DialContext: func(ctx context.Context, _, address string) (net.Conn, error) {
return Dial(ctx, network, address, options...)
},
MaxIdleConns: 100,
IdleConnTimeout: 90 * time.Second,
TLSHandshakeTimeout: 10 * time.Second,
ExpectContinueTimeout: 1 * time.Second,
}
}
// NewHTTPMultiTransport returns a new transport instance that uses the provided MultiDialer.
func NewHTTPMultiTransport(md *MultiDialer) *http.Transport {
return &http.Transport{
Proxy: http.ProxyFromEnvironment,
DialContext: func(ctx context.Context, _, address string) (net.Conn, error) {
host, _, _ := net.SplitHostPort(address)
return md.Dial(ctx, host)
},
MaxIdleConns: 100,
IdleConnTimeout: 90 * time.Second,
TLSHandshakeTimeout: 10 * time.Second,
ExpectContinueTimeout: 1 * time.Second,
}
}