From 11f4d90ff07de3557a86d78cb8623ad059633d04 Mon Sep 17 00:00:00 2001 From: Tom Clegg Date: Tue, 28 Jun 2022 15:40:26 -0400 Subject: [PATCH 1/1] 16561: Handle implicit port number in ws:// and wss:// urls. Arvados-DCO-1.1-Signed-off-by: Tom Clegg --- lib/service/cmd.go | 6 +++++- lib/service/cmd_test.go | 6 ++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/lib/service/cmd.go b/lib/service/cmd.go index 9e45e0f7e8..04c3e170ec 100644 --- a/lib/service/cmd.go +++ b/lib/service/cmd.go @@ -279,7 +279,11 @@ func getListenAddr(svcs arvados.Services, prog arvados.ServiceName, log logrus.F // explicit port name/number) means listen on // the well-known port for the specified // protocol, "foo.example:https". - listenAddr = net.JoinHostPort(listenAddr, listenURL.Scheme) + 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 { diff --git a/lib/service/cmd_test.go b/lib/service/cmd_test.go index 7a1f98a8f0..7db9109274 100644 --- a/lib/service/cmd_test.go +++ b/lib/service/cmd_test.go @@ -64,8 +64,6 @@ func (*Suite) TestGetListenAddress(c *check.C) { }, { // implicit port 80 in InternalURLs internalURLs: map[string]string{"http://localhost/": ""}, - expectListen: "http://localhost/", - expectInternal: "http://localhost/", expectErrorMatch: `.*:80: bind: permission denied`, }, { // implicit port 443 in InternalURLs @@ -73,6 +71,10 @@ func (*Suite) TestGetListenAddress(c *check.C) { expectListen: "http://localhost:" + unusedPort + "/", expectInternal: "https://host.example/", }, + { // implicit port 443 in ListenURL + internalURLs: map[string]string{"wss://host.example/": "wss://localhost/"}, + expectErrorMatch: `.*:443: bind: permission denied`, + }, { internalURLs: map[string]string{"https://hostname.example/": "http://localhost:8000/"}, expectListen: "http://localhost:8000/", -- 2.30.2