@@ -12,6 +12,7 @@ import (
1212
1313 "github.com/launchdarkly/go-server-sdk/v7/interfaces"
1414 "github.com/launchdarkly/go-server-sdk/v7/internal"
15+ "github.com/launchdarkly/go-server-sdk/v7/ldhttp"
1516 "github.com/launchdarkly/go-server-sdk/v7/subsystems"
1617
1718 helpers "github.com/launchdarkly/go-test-helpers/v3"
@@ -254,6 +255,119 @@ func TestHTTPConfigurationBuilder(t *testing.T) {
254255 })
255256 })
256257
258+ t .Run ("HTTPOptions with IdleConnTimeout" , func (t * testing.T ) {
259+ customTimeout := 45 * time .Second
260+ c , err := HTTPConfiguration ().
261+ HTTPOptions ([]ldhttp.TransportOption {ldhttp .IdleConnTimeoutOption (customTimeout )}).
262+ Build (basicConfig )
263+ require .NoError (t , err )
264+
265+ client := c .CreateHTTPClient ()
266+ require .NotNil (t , client .Transport )
267+ transport := client .Transport .(* http.Transport )
268+ assert .Equal (t , customTimeout , transport .IdleConnTimeout )
269+ })
270+
271+ t .Run ("HTTPOptions with MaxIdleConns" , func (t * testing.T ) {
272+ customMax := 50
273+ c , err := HTTPConfiguration ().
274+ HTTPOptions ([]ldhttp.TransportOption {ldhttp .MaxIdleConnsOption (customMax )}).
275+ Build (basicConfig )
276+ require .NoError (t , err )
277+
278+ client := c .CreateHTTPClient ()
279+ require .NotNil (t , client .Transport )
280+ transport := client .Transport .(* http.Transport )
281+ assert .Equal (t , customMax , transport .MaxIdleConns )
282+ })
283+
284+ t .Run ("HTTPOptions with MaxIdleConnsPerHost" , func (t * testing.T ) {
285+ customMax := 15
286+ c , err := HTTPConfiguration ().
287+ HTTPOptions ([]ldhttp.TransportOption {ldhttp .MaxIdleConnsPerHostOption (customMax )}).
288+ Build (basicConfig )
289+ require .NoError (t , err )
290+
291+ client := c .CreateHTTPClient ()
292+ require .NotNil (t , client .Transport )
293+ transport := client .Transport .(* http.Transport )
294+ assert .Equal (t , customMax , transport .MaxIdleConnsPerHost )
295+ })
296+
297+ t .Run ("HTTPOptions with DisableKeepAlives" , func (t * testing.T ) {
298+ c , err := HTTPConfiguration ().
299+ HTTPOptions ([]ldhttp.TransportOption {ldhttp .DisableKeepAlivesOption (true )}).
300+ Build (basicConfig )
301+ require .NoError (t , err )
302+
303+ client := c .CreateHTTPClient ()
304+ require .NotNil (t , client .Transport )
305+ transport := client .Transport .(* http.Transport )
306+ assert .True (t , transport .DisableKeepAlives )
307+ })
308+
309+ t .Run ("HTTPOptions with multiple transport options" , func (t * testing.T ) {
310+ customIdleTimeout := 30 * time .Second
311+ customMaxIdle := 75
312+ customMaxIdlePerHost := 20
313+
314+ c , err := HTTPConfiguration ().
315+ HTTPOptions ([]ldhttp.TransportOption {
316+ ldhttp .IdleConnTimeoutOption (customIdleTimeout ),
317+ ldhttp .MaxIdleConnsOption (customMaxIdle ),
318+ ldhttp .MaxIdleConnsPerHostOption (customMaxIdlePerHost ),
319+ ldhttp .DisableKeepAlivesOption (true ),
320+ }).
321+ Build (basicConfig )
322+ require .NoError (t , err )
323+
324+ client := c .CreateHTTPClient ()
325+ require .NotNil (t , client .Transport )
326+ transport := client .Transport .(* http.Transport )
327+ assert .Equal (t , customIdleTimeout , transport .IdleConnTimeout )
328+ assert .Equal (t , customMaxIdle , transport .MaxIdleConns )
329+ assert .Equal (t , customMaxIdlePerHost , transport .MaxIdleConnsPerHost )
330+ assert .True (t , transport .DisableKeepAlives )
331+ })
332+
333+ t .Run ("HTTPOptions combined with other builder methods" , func (t * testing.T ) {
334+ customIdleTimeout := 60 * time .Second
335+ customConnectTimeout := 5 * time .Second
336+
337+ c , err := HTTPConfiguration ().
338+ ConnectTimeout (customConnectTimeout ).
339+ HTTPOptions ([]ldhttp.TransportOption {ldhttp .IdleConnTimeoutOption (customIdleTimeout )}).
340+ Header ("Custom-Header" , "test-value" ).
341+ Build (basicConfig )
342+ require .NoError (t , err )
343+
344+ client := c .CreateHTTPClient ()
345+ assert .Equal (t , customConnectTimeout , client .Timeout )
346+
347+ require .NotNil (t , client .Transport )
348+ transport := client .Transport .(* http.Transport )
349+ assert .Equal (t , customIdleTimeout , transport .IdleConnTimeout )
350+
351+ assert .Equal (t , "test-value" , c .DefaultHeaders .Get ("Custom-Header" ))
352+ })
353+
354+ t .Run ("HTTPOptions called multiple times accumulates options" , func (t * testing.T ) {
355+ customIdleTimeout := 25 * time .Second
356+ customMaxIdle := 80
357+
358+ c , err := HTTPConfiguration ().
359+ HTTPOptions ([]ldhttp.TransportOption {ldhttp .IdleConnTimeoutOption (customIdleTimeout )}).
360+ HTTPOptions ([]ldhttp.TransportOption {ldhttp .MaxIdleConnsOption (customMaxIdle )}).
361+ Build (basicConfig )
362+ require .NoError (t , err )
363+
364+ client := c .CreateHTTPClient ()
365+ require .NotNil (t , client .Transport )
366+ transport := client .Transport .(* http.Transport )
367+ assert .Equal (t , customIdleTimeout , transport .IdleConnTimeout )
368+ assert .Equal (t , customMaxIdle , transport .MaxIdleConns )
369+ })
370+
257371 t .Run ("nil safety" , func (t * testing.T ) {
258372 var b * HTTPConfigurationBuilder = nil
259373 b = b .ConnectTimeout (0 ).Header ("a" , "b" ).ProxyURL ("c" ).Wrapper ("d" , "e" )
0 commit comments