WsWebSocketContainer::createRequestHeaders intends to check whether the port number is -1 or not. // Host header List<String> hostValues = new ArrayList<>(1); if (port == -1) { hostValues.add(host); } else { hostValues.add(host + ':' + port); } However, before createRequestHeaders method is called, the port number is set to 80 and 443 in connectToServerRecursive method. The value of port cannot be -1. if (port == -1) { if ("ws".equalsIgnoreCase(scheme)) { port = 80; } else { // Must be wss due to scheme validation above port = 443; } } I think it is side effect of revision 230c1083fd9f10ec50ccd1d15032f2df29e4de2c. (git-svn-id: https://svn.apache.org/repos/asf/tomcat/trunk@1780109 13f79535-47bb-0310-9956-ffa450edef68). It is better to remove the code.
The original purpose of the code was to include the port in the HTTP host header if a non-standard port was used. That requirement still exists but the refactoring to support proxing broke the previous implementation. I have now fixed this. Thanks for reporting this issue. Fixed in: - master for 9.0.27 onwards - 8.5.x for 8.5.47 onwards - 7.0.x for 7.0.97 onwards