@@ -296,6 +296,46 @@ func TestNewClientFromConfig(t *testing.T) {
296
296
fmt .Fprint (w , ExpectedMessage )
297
297
}
298
298
},
299
+ }, {
300
+ clientConfig : HTTPClientConfig {
301
+ FollowRedirects : true ,
302
+ TLSConfig : TLSConfig {
303
+ CAFile : TLSCAChainPath ,
304
+ CertFile : ClientCertificatePath ,
305
+ KeyFile : ClientKeyNoPassPath ,
306
+ ServerName : "" ,
307
+ InsecureSkipVerify : false },
308
+ },
309
+ handler : func (w http.ResponseWriter , r * http.Request ) {
310
+ switch r .URL .Path {
311
+ case "/redirected" :
312
+ fmt .Fprintf (w , ExpectedMessage )
313
+ default :
314
+ w .Header ().Set ("Location" , "/redirected" )
315
+ w .WriteHeader (http .StatusFound )
316
+ fmt .Fprintf (w , "It should follow the redirect." )
317
+ }
318
+ },
319
+ }, {
320
+ clientConfig : HTTPClientConfig {
321
+ FollowRedirects : false ,
322
+ TLSConfig : TLSConfig {
323
+ CAFile : TLSCAChainPath ,
324
+ CertFile : ClientCertificatePath ,
325
+ KeyFile : ClientKeyNoPassPath ,
326
+ ServerName : "" ,
327
+ InsecureSkipVerify : false },
328
+ },
329
+ handler : func (w http.ResponseWriter , r * http.Request ) {
330
+ switch r .URL .Path {
331
+ case "/redirected" :
332
+ fmt .Fprint (w , "The redirection was followed." )
333
+ default :
334
+ w .Header ().Set ("Location" , "/redirected" )
335
+ w .WriteHeader (http .StatusFound )
336
+ fmt .Fprintf (w , ExpectedMessage )
337
+ }
338
+ },
299
339
},
300
340
}
301
341
@@ -317,7 +357,7 @@ func TestNewClientFromConfig(t *testing.T) {
317
357
}
318
358
response , err := client .Get (testServer .URL )
319
359
if err != nil {
320
- t .Errorf ("Can't connect to the test server using this config: %+v" , validConfig .clientConfig )
360
+ t .Errorf ("Can't connect to the test server using this config: %+v: %v " , validConfig .clientConfig , err )
321
361
continue
322
362
}
323
363
@@ -941,6 +981,16 @@ func TestHideHTTPClientConfigSecrets(t *testing.T) {
941
981
}
942
982
}
943
983
984
+ func TestDefaultFollowRedirect (t * testing.T ) {
985
+ cfg , _ , err := LoadHTTPConfigFile ("testdata/http.conf.good.yml" )
986
+ if err != nil {
987
+ t .Errorf ("Error loading HTTP client config: %v" , err )
988
+ }
989
+ if ! cfg .FollowRedirects {
990
+ t .Errorf ("follow_redirects should be true" )
991
+ }
992
+ }
993
+
944
994
func TestValidateHTTPConfig (t * testing.T ) {
945
995
cfg , _ , err := LoadHTTPConfigFile ("testdata/http.conf.good.yml" )
946
996
if err != nil {
0 commit comments