forked from go-resty/resty
-
Notifications
You must be signed in to change notification settings - Fork 0
/
transport.go
33 lines (29 loc) · 937 Bytes
/
transport.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
// +build go1.13
// Copyright (c) 2015-2020 Jeevanandam M (jeeva@myjeeva.com), All rights reserved.
// resty source code and usage is governed by a MIT style
// license that can be found in the LICENSE file.
package resty
import (
"net"
"net/http"
"runtime"
)
func createTransport(localAddr net.Addr) *http.Transport {
dialer := &net.Dialer{
Timeout: DefaultTransportTimeout,
KeepAlive: DefaultTransportKeepAlive,
}
if localAddr != nil {
dialer.LocalAddr = localAddr
}
return &http.Transport{
Proxy: http.ProxyFromEnvironment,
DialContext: dialer.DialContext,
ForceAttemptHTTP2: true,
MaxIdleConns: DefaultTransportMaxIdleConns,
IdleConnTimeout: DefaultTransportIdleConnTimeout,
TLSHandshakeTimeout: DefaultTransportTLSHandshakeTimeout,
ExpectContinueTimeout: DefaultTransportExpectContinueTimeout,
MaxIdleConnsPerHost: runtime.GOMAXPROCS(0) + 1,
}
}