@@ -296,6 +296,44 @@ 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
+ http .Redirect (w , r , "/redirected" , http .StatusFound )
315
+ }
316
+ },
317
+ }, {
318
+ clientConfig : HTTPClientConfig {
319
+ FollowRedirects : false ,
320
+ TLSConfig : TLSConfig {
321
+ CAFile : TLSCAChainPath ,
322
+ CertFile : ClientCertificatePath ,
323
+ KeyFile : ClientKeyNoPassPath ,
324
+ ServerName : "" ,
325
+ InsecureSkipVerify : false },
326
+ },
327
+ handler : func (w http.ResponseWriter , r * http.Request ) {
328
+ switch r .URL .Path {
329
+ case "/redirected" :
330
+ fmt .Fprint (w , "The redirection was followed." )
331
+ default :
332
+ w .Header ()["Content-Type" ] = nil
333
+ http .Redirect (w , r , "/redirected" , http .StatusFound )
334
+ fmt .Fprint (w , ExpectedMessage )
335
+ }
336
+ },
299
337
},
300
338
}
301
339
@@ -317,7 +355,7 @@ func TestNewClientFromConfig(t *testing.T) {
317
355
}
318
356
response , err := client .Get (testServer .URL )
319
357
if err != nil {
320
- t .Errorf ("Can't connect to the test server using this config: %+v" , validConfig .clientConfig )
358
+ t .Errorf ("Can't connect to the test server using this config: %+v %v " , validConfig .clientConfig , err )
321
359
continue
322
360
}
323
361
@@ -932,6 +970,16 @@ func TestHideHTTPClientConfigSecrets(t *testing.T) {
932
970
}
933
971
}
934
972
973
+ func TestDefaultFollowRedirect (t * testing.T ) {
974
+ cfg , _ , err := LoadHTTPConfigFile ("testdata/http.conf.good.yml" )
975
+ if err != nil {
976
+ t .Errorf ("Error loading HTTP client config: %v" , err )
977
+ }
978
+ if ! cfg .FollowRedirects {
979
+ t .Errorf ("follow_redirects should be true" )
980
+ }
981
+ }
982
+
935
983
func TestValidateHTTPConfig (t * testing.T ) {
936
984
cfg , _ , err := LoadHTTPConfigFile ("testdata/http.conf.good.yml" )
937
985
if err != nil {
0 commit comments