Skip to content

Commit 87a6f0f

Browse files
committed
feat(enhancement): add MaxConnsPerHost setting into TransportSettings #1058 (#1069)
1 parent c4b634e commit 87a6f0f

3 files changed

Lines changed: 8 additions & 0 deletions

File tree

client.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,9 @@ type TransportSettings struct {
141141
// MaxIdleConnsPerHost, default value is `runtime.GOMAXPROCS(0) + 1`.
142142
MaxIdleConnsPerHost int
143143

144+
// MaxConnsPerHost, default value is no limit.
145+
MaxConnsPerHost int
146+
144147
// DisableKeepAlives, default value is `false`.
145148
DisableKeepAlives bool
146149

client_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -971,6 +971,7 @@ func TestCustomTransportSettings(t *testing.T) {
971971
ExpectContinueTimeout: 1 * time.Second,
972972
MaxIdleConns: 50,
973973
MaxIdleConnsPerHost: 3,
974+
MaxConnsPerHost: 100,
974975
ResponseHeaderTimeout: 10 * time.Second,
975976
MaxResponseHeaderBytes: 1 << 10,
976977
WriteBufferSize: 2 << 10,

resty.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,10 @@ func createTransport(dialer *net.Dialer, transportSettings *TransportSettings) *
127127
t.MaxIdleConnsPerHost = runtime.GOMAXPROCS(0) + 1
128128
}
129129

130+
if transportSettings.MaxConnsPerHost > 0 {
131+
t.MaxConnsPerHost = transportSettings.MaxConnsPerHost
132+
}
133+
130134
//
131135
// No default value in Resty for following settings, added to
132136
// provide ability to set value otherwise the Go HTTP client

0 commit comments

Comments
 (0)