Skip to content

Instantly share code, notes, and snippets.

@niko-dunixi
Created June 4, 2024 17:45
Show Gist options
  • Save niko-dunixi/d4824b6dd810aecf2ca99ae5e8d635a0 to your computer and use it in GitHub Desktop.
Save niko-dunixi/d4824b6dd810aecf2ca99ae5e8d635a0 to your computer and use it in GitHub Desktop.
Common Golang Http Client Configurations
// https://medium.com/@nate510/don-t-use-go-s-default-http-client-4804cb19f779
client := &http.Client{
Timeout: time.Second * 10,
Transport: &http.Transport{
Dial: (&net.Dialer{
Timeout: 5 * time.Second,
}).Dial,
TLSHandshakeTimeout: 5 * time.Second,
},
}
// https://stackoverflow.com/a/53369584/1478636
import (
"golang.org/x/net/http2"
)
client := &http.Client{
Timeout: time.Second * 10,
Transport: &http2.Transport{
AllowHTTP: true,
DialTLS: func(netw, addr string, cfg *tls.Config) (net.Conn, error) {
return net.Dial(netw, addr)
},
},
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment