Skip to content

Commit 4d0b088

Browse files
atoulmemx-psi
andauthored
[chore] set default transport defaults on NewDefaultClientConfig (#10688)
#### Description Set the defaults on `NewDefaultClientConfig`. This change is a no-op since those defaults are set if the value is not set. Add documentation to all fields as well. #### Link to tracking issue #9478 --------- Co-authored-by: Pablo Baeyens <[email protected]>
1 parent 26fb7cb commit 4d0b088

File tree

1 file changed

+16
-9
lines changed

1 file changed

+16
-9
lines changed

config/confighttp/confighttp.go

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,15 @@ type ClientConfig struct {
4747
TLSSetting configtls.ClientConfig `mapstructure:"tls"`
4848

4949
// ReadBufferSize for HTTP client. See http.Transport.ReadBufferSize.
50+
// Default is 0.
5051
ReadBufferSize int `mapstructure:"read_buffer_size"`
5152

5253
// WriteBufferSize for HTTP client. See http.Transport.WriteBufferSize.
54+
// Default is 0.
5355
WriteBufferSize int `mapstructure:"write_buffer_size"`
5456

5557
// Timeout parameter configures `http.Client.Timeout`.
58+
// Default is 0 (unlimited).
5659
Timeout time.Duration `mapstructure:"timeout"`
5760

5861
// Additional headers attached to each HTTP request sent by the client.
@@ -67,20 +70,20 @@ type ClientConfig struct {
6770
Compression configcompression.Type `mapstructure:"compression"`
6871

6972
// MaxIdleConns is used to set a limit to the maximum idle HTTP connections the client can keep open.
70-
// There's an already set value, and we want to override it only if an explicit value provided
73+
// By default, it is set to 100.
7174
MaxIdleConns *int `mapstructure:"max_idle_conns"`
7275

7376
// MaxIdleConnsPerHost is used to set a limit to the maximum idle HTTP connections the host can keep open.
74-
// There's an already set value, and we want to override it only if an explicit value provided
77+
// By default, it is set to [http.DefaultTransport.MaxIdleConnsPerHost].
7578
MaxIdleConnsPerHost *int `mapstructure:"max_idle_conns_per_host"`
7679

7780
// MaxConnsPerHost limits the total number of connections per host, including connections in the dialing,
7881
// active, and idle states.
79-
// There's an already set value, and we want to override it only if an explicit value provided
82+
// By default, it is set to [http.DefaultTransport.MaxConnsPerHost].
8083
MaxConnsPerHost *int `mapstructure:"max_conns_per_host"`
8184

8285
// IdleConnTimeout is the maximum amount of time a connection will remain open before closing itself.
83-
// There's an already set value, and we want to override it only if an explicit value provided
86+
// By default, it is set to [http.DefaultTransport.IdleConnTimeout]
8487
IdleConnTimeout *time.Duration `mapstructure:"idle_conn_timeout"`
8588

8689
// DisableKeepAlives, if true, disables HTTP keep-alives and will only use the connection to the server
@@ -111,17 +114,21 @@ type CookiesConfig struct {
111114
}
112115

113116
// NewDefaultClientConfig returns ClientConfig type object with
114-
// the default values of 'MaxIdleConns' and 'IdleConnTimeout'.
117+
// the default values of 'MaxIdleConns' and 'IdleConnTimeout', as well as [http.DefaultTransport] values.
115118
// Other config options are not added as they are initialized with 'zero value' by GoLang as default.
116119
// We encourage to use this function to create an object of ClientConfig.
117120
func NewDefaultClientConfig() ClientConfig {
118121
// The default values are taken from the values of 'DefaultTransport' of 'http' package.
119-
maxIdleConns := 100
120-
idleConnTimeout := 90 * time.Second
122+
defaultTransport := http.DefaultTransport.(*http.Transport)
121123

122124
return ClientConfig{
123-
MaxIdleConns: &maxIdleConns,
124-
IdleConnTimeout: &idleConnTimeout,
125+
ReadBufferSize: defaultTransport.ReadBufferSize,
126+
WriteBufferSize: defaultTransport.WriteBufferSize,
127+
Headers: map[string]configopaque.String{},
128+
MaxIdleConns: &defaultTransport.MaxIdleConns,
129+
MaxIdleConnsPerHost: &defaultTransport.MaxIdleConnsPerHost,
130+
MaxConnsPerHost: &defaultTransport.MaxConnsPerHost,
131+
IdleConnTimeout: &defaultTransport.IdleConnTimeout,
125132
}
126133
}
127134

0 commit comments

Comments
 (0)