diff --git a/client.go b/client.go index 1976ba72..56466aba 100644 --- a/client.go +++ b/client.go @@ -141,6 +141,9 @@ type TransportSettings struct { // MaxIdleConnsPerHost, default value is `runtime.GOMAXPROCS(0) + 1`. MaxIdleConnsPerHost int + // MaxConnsPerHost, default value is no limit. + MaxConnsPerHost int + // DisableKeepAlives, default value is `false`. DisableKeepAlives bool diff --git a/client_test.go b/client_test.go index 6aa92e68..412ecdec 100644 --- a/client_test.go +++ b/client_test.go @@ -971,6 +971,7 @@ func TestCustomTransportSettings(t *testing.T) { ExpectContinueTimeout: 1 * time.Second, MaxIdleConns: 50, MaxIdleConnsPerHost: 3, + MaxConnsPerHost: 100, ResponseHeaderTimeout: 10 * time.Second, MaxResponseHeaderBytes: 1 << 10, WriteBufferSize: 2 << 10, diff --git a/resty.go b/resty.go index 677b6463..938b70cf 100644 --- a/resty.go +++ b/resty.go @@ -127,6 +127,10 @@ func createTransport(dialer *net.Dialer, transportSettings *TransportSettings) * t.MaxIdleConnsPerHost = runtime.GOMAXPROCS(0) + 1 } + if transportSettings.MaxConnsPerHost > 0 { + t.MaxConnsPerHost = transportSettings.MaxConnsPerHost + } + // // No default value in Resty for following settings, added to // provide ability to set value otherwise the Go HTTP client