Author: markt Date: Tue Aug 7 20:18:51 2018 New Revision: 1837613 URL: http://svn.apache.org/viewvc?rev=1837613&view=rev Log: Fix https://bz.apache.org/bugzilla/show_bug.cgi?id=62596 Remove the limit on the size of the initial HTTP upgrade request used to establish the web socket connection.
Modified: tomcat/trunk/java/org/apache/tomcat/websocket/WsWebSocketContainer.java tomcat/trunk/test/org/apache/tomcat/websocket/TestWebSocketFrameClient.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=1837613&r1=1837612&r2=1837613&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/tomcat/websocket/WsWebSocketContainer.java (original) +++ tomcat/trunk/java/org/apache/tomcat/websocket/WsWebSocketContainer.java Tue Aug 7 20:18:51 2018 @@ -733,7 +733,7 @@ public class WsWebSocketContainer implem // Headers for (Entry<String, List<String>> entry : reqHeaders.entrySet()) { - addHeader(result, entry.getKey(), entry.getValue()); + result = addHeader(result, entry.getKey(), entry.getValue()); } // Terminating CRLF @@ -745,15 +745,34 @@ public class WsWebSocketContainer implem } - private static void addHeader(ByteBuffer result, String key, List<String> values) { + private static ByteBuffer addHeader(ByteBuffer result, String key, List<String> values) { if (values.isEmpty()) { - return; + return result; } - result.put(key.getBytes(StandardCharsets.ISO_8859_1)); - result.put(": ".getBytes(StandardCharsets.ISO_8859_1)); - result.put(StringUtils.join(values).getBytes(StandardCharsets.ISO_8859_1)); - result.put(CRLF); + result = putWithExpand(result, key.getBytes(StandardCharsets.ISO_8859_1)); + result = putWithExpand(result, ": ".getBytes(StandardCharsets.ISO_8859_1)); + result = putWithExpand(result, StringUtils.join(values).getBytes(StandardCharsets.ISO_8859_1)); + result = putWithExpand(result, CRLF); + + return result; + } + + + private static ByteBuffer putWithExpand(ByteBuffer input, byte[] bytes) { + if (bytes.length > input.remaining()) { + int newSize; + if (bytes.length > input.capacity()) { + newSize = 2 * bytes.length; + } else { + newSize = input.capacity() * 2; + } + ByteBuffer expanded = ByteBuffer.allocate(newSize); + input.flip(); + expanded.put(input); + input = expanded; + } + return input.put(bytes); } Modified: tomcat/trunk/test/org/apache/tomcat/websocket/TestWebSocketFrameClient.java URL: http://svn.apache.org/viewvc/tomcat/trunk/test/org/apache/tomcat/websocket/TestWebSocketFrameClient.java?rev=1837613&r1=1837612&r2=1837613&view=diff ============================================================================== --- tomcat/trunk/test/org/apache/tomcat/websocket/TestWebSocketFrameClient.java (original) +++ tomcat/trunk/test/org/apache/tomcat/websocket/TestWebSocketFrameClient.java Tue Aug 7 20:18:51 2018 @@ -17,11 +17,15 @@ package org.apache.tomcat.websocket; import java.net.URI; +import java.util.Collections; +import java.util.List; +import java.util.Map; import java.util.Queue; import java.util.concurrent.CountDownLatch; import java.util.concurrent.TimeUnit; import javax.websocket.ClientEndpointConfig; +import javax.websocket.ClientEndpointConfig.Configurator; import javax.websocket.ContainerProvider; import javax.websocket.Session; import javax.websocket.WebSocketContainer; @@ -57,10 +61,19 @@ public class TestWebSocketFrameClient ex tomcat.start(); - WebSocketContainer wsContainer = - ContainerProvider.getWebSocketContainer(); + WebSocketContainer wsContainer = ContainerProvider.getWebSocketContainer(); + + // BZ 62596 ClientEndpointConfig clientEndpointConfig = - ClientEndpointConfig.Builder.create().build(); + ClientEndpointConfig.Builder.create().configurator(new Configurator() { + @Override + public void beforeRequest(Map<String, List<String>> headers) { + headers.put("Dummy", Collections.singletonList( + String.join("", Collections.nCopies(4000, "A")))); + super.beforeRequest(headers); + } + }).build(); + Session wsSession = wsContainer.connectToServer( TesterProgrammaticEndpoint.class, clientEndpointConfig, Modified: tomcat/trunk/webapps/docs/changelog.xml URL: http://svn.apache.org/viewvc/tomcat/trunk/webapps/docs/changelog.xml?rev=1837613&r1=1837612&r2=1837613&view=diff ============================================================================== --- tomcat/trunk/webapps/docs/changelog.xml (original) +++ tomcat/trunk/webapps/docs/changelog.xml Tue Aug 7 20:18:51 2018 @@ -159,6 +159,14 @@ </fix> </changelog> </subsection> + <subseciton name="WebSocket"> + <changelog> + <fix> + <bug>62596</bug>: Remove the limit on the size of the initial HTTP + upgrade request used to establish the web socket connection. (markt) + </fix> + </changelog> + </subseciton> <subsection name="Web applications"> <changelog> <add> --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org