Last active
November 17, 2020 08:57
-
-
Save whiler/37bce7eb13fbdd39d385b8d156bbf294 to your computer and use it in GitHub Desktop.
default http client in golang
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
transport := &http.Transport{ | |
Proxy: http.ProxyFromEnvironment, | |
DialContext: (&net.Dialer{ | |
Timeout: 5 * time.Second, | |
KeepAlive: 30 * time.Second, | |
}).DialContext, | |
TLSHandshakeTimeout: 5 * time.Second, | |
ExpectContinueTimeout: 5 * time.Second, | |
ResponseHeaderTimeout: 7 * time.Second, | |
IdleConnTimeout: 5 * time.Second, | |
MaxIdleConns: 10, | |
MaxIdleConnsPerHost: 2, | |
ForceAttemptHTTP2: true, | |
} | |
http2.ConfigureTransport(transport) | |
httpc := &http.Client{Transport: transport} | |
defer httpc.CloseIdleConnections() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment