@@ -296,6 +296,46 @@ func TestNewClientFromConfig(t *testing.T) {
296296 fmt .Fprint (w , ExpectedMessage )
297297 }
298298 },
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+ },
299339 },
300340 }
301341
@@ -317,7 +357,7 @@ func TestNewClientFromConfig(t *testing.T) {
317357 }
318358 response , err := client .Get (testServer .URL )
319359 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 )
321361 continue
322362 }
323363
@@ -941,6 +981,16 @@ func TestHideHTTPClientConfigSecrets(t *testing.T) {
941981 }
942982}
943983
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+
944994func TestValidateHTTPConfig (t * testing.T ) {
945995 cfg , _ , err := LoadHTTPConfigFile ("testdata/http.conf.good.yml" )
946996 if err != nil {
0 commit comments