Skip to content

Commit 299a6ec

Browse files
committed
Ensure that the hostname has a port number when building pushpin routes
1 parent f0a46b9 commit 299a6ec

1 file changed

Lines changed: 21 additions & 1 deletion

File tree

pkg/commands/compute/serve.go

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -738,7 +738,7 @@ func (c *ServeCommand) BuildPushpinRoutes() []string {
738738
}
739739

740740
// Target:
741-
target := u.Host
741+
target := normalizeHost(u)
742742
// 1. `over_http`: Enable WebSocket-over-HTTP
743743
target += ",over_http"
744744
// 2. `ssl`: If backend is https
@@ -758,6 +758,26 @@ func (c *ServeCommand) BuildPushpinRoutes() []string {
758758
return routes
759759
}
760760

761+
func normalizeHost(u *url.URL) string {
762+
host := u.Host
763+
764+
// If Host already has a port, SplitHostPort succeeds
765+
// This an attempt at future-proofing as it handles IPv6
766+
if _, _, err := net.SplitHostPort(host); err == nil {
767+
return host
768+
}
769+
770+
switch u.Scheme {
771+
case "https":
772+
return net.JoinHostPort(host, "443")
773+
case "http":
774+
return net.JoinHostPort(host, "80")
775+
default:
776+
// Unknown scheme, leave untouched
777+
return host
778+
}
779+
}
780+
761781
func formatPushpinLog(line string) (string, string) {
762782
level := "INFO"
763783
msg := line

0 commit comments

Comments
 (0)