diff --git a/api.go b/api.go index a8318e0ee2..24e75ff368 100644 --- a/api.go +++ b/api.go @@ -875,10 +875,16 @@ func (c *Client) makeTargetURL(bucketName, objectName, bucketLocation string, is if h, p, err := net.SplitHostPort(host); err == nil { if scheme == "http" && p == "80" || scheme == "https" && p == "443" { host = h + if ip := net.ParseIP(h); ip != nil { + if ip.To16() != nil { + host = "[" + h + "]" + } + } } } urlStr := scheme + "://" + host + "/" + // Make URL only if bucketName is available, otherwise use the // endpoint URL. if bucketName != "" { diff --git a/api_unit_test.go b/api_unit_test.go index dadfeeb85c..3defca2026 100644 --- a/api_unit_test.go +++ b/api_unit_test.go @@ -196,6 +196,8 @@ func TestMakeTargetURL(t *testing.T) { {"localhost:80", false, "mybucket", "myobject", "", nil, url.URL{Host: "localhost", Scheme: "http", Path: "/mybucket/myobject"}, nil}, // Test 9, testing with port 443 {"localhost:443", true, "mybucket", "myobject", "", nil, url.URL{Host: "localhost", Scheme: "https", Path: "/mybucket/myobject"}, nil}, + {"[240b:c0e0:102:54C0:1c05:c2c1:19:5001]:443", true, "mybucket", "myobject", "", nil, url.URL{Host: "[240b:c0e0:102:54C0:1c05:c2c1:19:5001]", Scheme: "https", Path: "/mybucket/myobject"}, nil}, + {"[240b:c0e0:102:54C0:1c05:c2c1:19:5001]:9000", true, "mybucket", "myobject", "", nil, url.URL{Host: "[240b:c0e0:102:54C0:1c05:c2c1:19:5001]:9000", Scheme: "https", Path: "/mybucket/myobject"}, nil}, } for i, testCase := range testCases {