This is an automated email from the ASF dual-hosted git repository.
markt pushed a commit to branch 8.5.x
in repository https://gitbox.apache.org/repos/asf/tomcat.git
The following commit(s) were added to refs/heads/8.5.x by this push:
new 831c6e1 Fix https://bz.apache.org/bugzilla/show_bug.cgi?id=63753 WS
host header
831c6e1 is described below
commit 831c6e16d4378e5523bbd238087cd5eb089b23bf
Author: Mark Thomas <[email protected]>
AuthorDate: Thu Sep 19 14:46:09 2019 +0100
Fix https://bz.apache.org/bugzilla/show_bug.cgi?id=63753 WS host header
Ensure that the Host header in a Web Socket HTTP upgrade request only
contains a port if a non-default port is being used.
---
java/org/apache/tomcat/websocket/WsWebSocketContainer.java | 7 ++++---
webapps/docs/changelog.xml | 9 +++++++++
2 files changed, 13 insertions(+), 3 deletions(-)
diff --git a/java/org/apache/tomcat/websocket/WsWebSocketContainer.java
b/java/org/apache/tomcat/websocket/WsWebSocketContainer.java
index f19c1b2..9275e15 100644
--- a/java/org/apache/tomcat/websocket/WsWebSocketContainer.java
+++ b/java/org/apache/tomcat/websocket/WsWebSocketContainer.java
@@ -265,7 +265,7 @@ public class WsWebSocketContainer implements
WebSocketContainer, BackgroundProce
}
// Create the initial HTTP request to open the WebSocket connection
- Map<String, List<String>> reqHeaders = createRequestHeaders(host, port,
+ Map<String, List<String>> reqHeaders = createRequestHeaders(host,
port, secure,
clientEndpointConfiguration);
clientEndpointConfiguration.getConfigurator().beforeRequest(reqHeaders);
if (Constants.DEFAULT_ORIGIN_HEADER_VALUE != null
@@ -631,7 +631,7 @@ public class WsWebSocketContainer implements
WebSocketContainer, BackgroundProce
}
private static Map<String, List<String>> createRequestHeaders(String host,
int port,
- ClientEndpointConfig clientEndpointConfiguration) {
+ boolean secure, ClientEndpointConfig clientEndpointConfiguration) {
Map<String, List<String>> headers = new HashMap<>();
List<Extension> extensions =
clientEndpointConfiguration.getExtensions();
@@ -646,7 +646,8 @@ public class WsWebSocketContainer implements
WebSocketContainer, BackgroundProce
// Host header
List<String> hostValues = new ArrayList<>(1);
- if (port == -1) {
+ if (port == 80 && !secure || port == 443 && secure) {
+ // Default ports. Do not include port in host header
hostValues.add(host);
} else {
hostValues.add(host + ':' + port);
diff --git a/webapps/docs/changelog.xml b/webapps/docs/changelog.xml
index 0b02f95..34cf200 100644
--- a/webapps/docs/changelog.xml
+++ b/webapps/docs/changelog.xml
@@ -54,6 +54,15 @@
</fix>
</changelog>
</subsection>
+ <subsection name="Web Socket">
+ <changelog>
+ <fix>
+ <bug>63753</bug>: Ensure that the <code>Host</code> header in a Web
+ Socket HTTP upgrade request only contains a port if a non-default port
+ is being used. (markt)
+ </fix>
+ </changelog>
+ </subsection>
<subsection name="Other">
<changelog>
<scode>
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]