Skip to content

Commit

Permalink
Merge pull request #9403 from influxdata/js-9259-influx-cli-port-fix
Browse files Browse the repository at this point in the history
Do not explicitly specify ports 80 or 443 when they are the default port
  • Loading branch information
jsternberg authored Feb 8, 2018
2 parents 0af6fb8 + fab5c70 commit c6d01e3
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 2 deletions.
8 changes: 6 additions & 2 deletions client/influxdb.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,13 +84,17 @@ func ParseConnectionString(path string, ssl bool) (url.URL, error) {

u := url.URL{
Scheme: "http",
Host: host,
}
if ssl {
u.Scheme = "https"
if port != 443 {
u.Host = net.JoinHostPort(host, strconv.Itoa(port))
}
} else if port != 80 {
u.Host = net.JoinHostPort(host, strconv.Itoa(port))
}

u.Host = net.JoinHostPort(host, strconv.Itoa(port))

return u, nil
}

Expand Down
55 changes: 55 additions & 0 deletions client/influxdb_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -746,6 +746,61 @@ func TestClient_NoTimeout(t *testing.T) {
}
}

func TestClient_ParseConnectionString(t *testing.T) {
for _, tt := range []struct {
addr string
ssl bool
exp string
}{
{
addr: "localhost",
exp: "http://localhost:8086",
},
{
addr: "localhost:8086",
exp: "http://localhost:8086",
},
{
addr: "localhost:80",
exp: "http://localhost",
},
{
addr: "localhost",
exp: "https://localhost:8086",
ssl: true,
},
{
addr: "localhost:443",
exp: "https://localhost",
ssl: true,
},
{
addr: "localhost:80",
exp: "https://localhost:80",
ssl: true,
},
{
addr: "localhost:443",
exp: "http://localhost:443",
},
} {
name := tt.addr
if tt.ssl {
name += "+ssl"
}
t.Run(name, func(t *testing.T) {
u, err := client.ParseConnectionString(tt.addr, tt.ssl)
if err != nil {
t.Fatalf("unexpected error: %s", err)
}

if got, want := u.String(), tt.exp; got != want {
t.Fatalf("unexpected connection string: got=%s want=%s", got, want)
}
})
}
}

func TestClient_ParseConnectionString_IPv6(t *testing.T) {
path := "[fdf5:9ede:1875:0:a9ee:a600:8fe3:d495]:8086"
u, err := client.ParseConnectionString(path, false)
Expand Down

0 comments on commit c6d01e3

Please sign in to comment.