16561: Handle implicit port number in ws:// and wss:// urls.
[arvados.git] / lib / service / cmd.go
index b5e395bec828c879a9e86ac646cf82026873422c..04c3e170ec6e093bac2e701e51e06894aa42009c 100644 (file)
@@ -273,7 +273,19 @@ func getListenAddr(svcs arvados.Services, prog arvados.ServiceName, log logrus.F
                        // intermediate proxy/routing)
                        listenURL = internalURL
                }
-               listener, err := net.Listen("tcp", listenURL.Host)
+               listenAddr := listenURL.Host
+               if _, _, err := net.SplitHostPort(listenAddr); err != nil {
+                       // url "https://foo.example/" (with no
+                       // explicit port name/number) means listen on
+                       // the well-known port for the specified
+                       // protocol, "foo.example:https".
+                       port := listenURL.Scheme
+                       if port == "ws" || port == "wss" {
+                               port = "http" + port[2:]
+                       }
+                       listenAddr = net.JoinHostPort(listenAddr, port)
+               }
+               listener, err := net.Listen("tcp", listenAddr)
                if err == nil {
                        listener.Close()
                        return listenURL, internalURL, nil