Skip to content

Instantly share code, notes, and snippets.

@whiler
Last active November 17, 2020 08:57
Show Gist options
  • Save whiler/37bce7eb13fbdd39d385b8d156bbf294 to your computer and use it in GitHub Desktop.
Save whiler/37bce7eb13fbdd39d385b8d156bbf294 to your computer and use it in GitHub Desktop.
default http client in golang
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