Skip to content

Commit

Permalink
fix: Send correct host header when an endpoint is IPv4 (#1835)
Browse files Browse the repository at this point in the history
Currently, when the specified endpoint is an IP v4 address and
the port is 80/443, minio-go sends a Host header with a bracket,
which is wrong.

An ipV4 can be converted to ip6 in Golang library, therefore using
ip.To4() should return nil if the passed IP is v6.
  • Loading branch information
vadmeste committed May 30, 2023
1 parent ba04019 commit 68418bf
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion api.go
Original file line number Diff line number Diff line change
Expand Up @@ -919,7 +919,7 @@ 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 && ip.To16() != nil {
if ip := net.ParseIP(h); ip != nil && ip.To4() == nil {
host = "[" + h + "]"
}
}
Expand Down

0 comments on commit 68418bf

Please sign in to comment.