Author: markt
Date: Tue Jan 24 20:20:11 2017
New Revision: 1780109

URL: http://svn.apache.org/viewvc?rev=1780109&view=rev
Log:
Correctly create a CONNECT request when establishing a WebSocket connection via 
a proxy.
Patch provided by Svetlin Zarev.
This closes #39

Modified:
    tomcat/trunk/java/org/apache/tomcat/websocket/WsWebSocketContainer.java
    tomcat/trunk/webapps/docs/changelog.xml

Modified: 
tomcat/trunk/java/org/apache/tomcat/websocket/WsWebSocketContainer.java
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/websocket/WsWebSocketContainer.java?rev=1780109&r1=1780108&r2=1780109&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/tomcat/websocket/WsWebSocketContainer.java 
(original)
+++ tomcat/trunk/java/org/apache/tomcat/websocket/WsWebSocketContainer.java Tue 
Jan 24 20:20:11 2017
@@ -236,18 +236,20 @@ public class WsWebSocketContainer implem
             }
         }
 
-        // If sa is null, no proxy is configured so need to create sa
-        if (sa == null) {
-            if (port == -1) {
-                if ("ws".equalsIgnoreCase(scheme)) {
-                    sa = new InetSocketAddress(host, 80);
-                } else {
-                    // Must be wss due to scheme validation above
-                    sa = new InetSocketAddress(host, 443);
-                }
+        // If the port is not explicitly specified, compute it based on the
+        // scheme
+        if (port == -1) {
+            if ("ws".equalsIgnoreCase(scheme)) {
+                port = 80;
             } else {
-                sa = new InetSocketAddress(host, port);
+                // Must be wss due to scheme validation above
+                port = 443;
             }
+        }
+
+        // If sa is null, no proxy is configured so need to create sa
+        if (sa == null) {
+            sa = new InetSocketAddress(host, port);
         } else {
             proxyConnect = createProxyRequest(host, port);
         }
@@ -450,16 +452,14 @@ public class WsWebSocketContainer implem
         StringBuilder request = new StringBuilder();
         request.append("CONNECT ");
         request.append(host);
-        if (port != -1) {
-            request.append(':');
-            request.append(port);
-        }
+        request.append(':');
+        request.append(port);
+
         request.append(" HTTP/1.1\r\nProxy-Connection: 
keep-alive\r\nConnection: keepalive\r\nHost: ");
         request.append(host);
-        if (port != -1) {
-            request.append(':');
-            request.append(port);
-        }
+        request.append(':');
+        request.append(port);
+
         request.append("\r\n\r\n");
 
         byte[] bytes = 
request.toString().getBytes(StandardCharsets.ISO_8859_1);

Modified: tomcat/trunk/webapps/docs/changelog.xml
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/webapps/docs/changelog.xml?rev=1780109&r1=1780108&r2=1780109&view=diff
==============================================================================
--- tomcat/trunk/webapps/docs/changelog.xml (original)
+++ tomcat/trunk/webapps/docs/changelog.xml Tue Jan 24 20:20:11 2017
@@ -92,6 +92,15 @@
       </add>
     </changelog>
   </subsection>
+  <subsection name="WebSocket">
+    <changelog>
+      <fix>
+        <bug>60617</bug>: Correctly create a <code>CONNECT</code> request when
+        establishing a WebSocket connection via a proxy. Patch provided by
+        Svetlin Zarev. (markt)
+      </fix>
+    </changelog>
+  </subsection>
   <subsection name="Tribes">
     <changelog>
       <add>



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org
For additional commands, e-mail: dev-h...@tomcat.apache.org

Reply via email to