Skip to content

Commit

Permalink
fix: ipv6 support without 'port' add missing brackets
Browse files Browse the repository at this point in the history
  • Loading branch information
harshavardhana committed Feb 22, 2022
1 parent 98a40db commit 9ab24c4
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
6 changes: 6 additions & 0 deletions api.go
Expand Up @@ -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 != "" {
Expand Down
2 changes: 2 additions & 0 deletions api_unit_test.go
Expand Up @@ -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 {
Expand Down

0 comments on commit 9ab24c4

Please sign in to comment.