Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not explicitly specify ports 80 or 443 when they are the default port #9403

Merged
merged 1 commit into from
Feb 8, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Do not explicitly specify ports 80 or 443 when they are the default port
The default port for HTTP is 80 and HTTPS is 443. When you host InfluxDB
on a service that uses a reverse proxy, the `Host` header needs to be
exactly correct. Since the host header isn't expecting to see the port
when it is the default, this causes routing to fail.
  • Loading branch information
jsternberg committed Feb 8, 2018
commit fab5c70f6d400708649f7ef57ce90096d7e6e78c
8 changes: 6 additions & 2 deletions client/influxdb.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,13 +83,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