Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

httputil: allow creating new default transports #34

Merged
merged 1 commit into from
Nov 5, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 18 additions & 12 deletions pkg/httputil/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,26 @@ import (

const DefaultTimeout = time.Second * 15

// NewDefaultTransport returns a new default [http.Transport] with a 15 second
// dial and TLS handshake timeout and HTTP/2 support disabled.
func NewDefaultTransport() *http.Transport {
return &http.Transport{
Proxy: http.ProxyFromEnvironment,
Dial: (&net.Dialer{
Timeout: DefaultTimeout,
KeepAlive: 30 * time.Second,
}).Dial,
ForceAttemptHTTP2: false, // never use HTTP/2
MaxIdleConns: 100,
IdleConnTimeout: 90 * time.Second,
TLSHandshakeTimeout: DefaultTimeout,
ExpectContinueTimeout: 1 * time.Second,
}
}

// DeafultTransport is a http.Transport with a 15 second dial and TLS handshake
// timeout and HTTP/2 support disabled.
var DefaultTransport = &http.Transport{
Proxy: http.ProxyFromEnvironment,
Dial: (&net.Dialer{
Timeout: DefaultTimeout,
KeepAlive: 30 * time.Second,
}).Dial,
ForceAttemptHTTP2: false, // never use HTTP/2
MaxIdleConns: 100,
IdleConnTimeout: 90 * time.Second,
TLSHandshakeTimeout: DefaultTimeout,
ExpectContinueTimeout: 1 * time.Second,
}
var DefaultTransport = NewDefaultTransport()

// DefaultClient is a http.Client using the DefaultTransport.
var DefaultClient = &http.Client{
Expand Down
Loading