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

HTTP client: Expose KeepAlive to end users #693

Closed
wants to merge 1 commit into from
Closed
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
7 changes: 6 additions & 1 deletion config/http_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ var (
DefaultHTTPClientConfig = HTTPClientConfig{
FollowRedirects: true,
EnableHTTP2: true,
EnableKeepAlive: true,
}

// defaultHTTPClientOptions holds the default HTTP client options.
Expand Down Expand Up @@ -324,6 +325,10 @@ type HTTPClientConfig struct {
// HTTPHeaders specify headers to inject in the requests. Those headers
// could be marshalled back to the users.
HTTPHeaders *Headers `yaml:"http_headers,omitempty" json:"http_headers,omitempty"`
// EnableKeepAlive determines whether to reuse TCP connections for multiple
// requests. If true, it keeps connections open, improving performance. If
// false, it closes connections after each request.
EnableKeepAlive bool `yaml:"enable_keepalive" json:"enable_keepalive"`
}

// SetDirectory joins any relative file paths with dir.
Expand Down Expand Up @@ -593,7 +598,7 @@ func NewRoundTripperFromConfigWithContext(ctx context.Context, cfg HTTPClientCon
ProxyConnectHeader: cfg.ProxyConfig.GetProxyConnectHeader(),
MaxIdleConns: 20000,
MaxIdleConnsPerHost: 1000, // see https://github.com/golang/go/issues/13801
DisableKeepAlives: !opts.keepAlivesEnabled,
DisableKeepAlives: !cfg.EnableKeepAlive && !opts.keepAlivesEnabled,
TLSClientConfig: tlsConfig,
DisableCompression: true,
IdleConnTimeout: opts.idleConnTimeout,
Expand Down