Author: markt Date: Tue Jun 2 12:58:37 2015 New Revision: 1683096 URL: http://svn.apache.org/r1683096 Log: Correctly implement the section 3.2.1 test, add a new one and then fix the bug they highlight.
Modified: tomcat/trunk/java/org/apache/coyote/UpgradeProtocol.java tomcat/trunk/java/org/apache/coyote/http11/Http11Processor.java tomcat/trunk/java/org/apache/coyote/http2/Http2Protocol.java tomcat/trunk/test/org/apache/coyote/http2/TestHttp2Section_3_2_1.java Modified: tomcat/trunk/java/org/apache/coyote/UpgradeProtocol.java URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/coyote/UpgradeProtocol.java?rev=1683096&r1=1683095&r2=1683096&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/coyote/UpgradeProtocol.java (original) +++ tomcat/trunk/java/org/apache/coyote/UpgradeProtocol.java Tue Jun 2 12:58:37 2015 @@ -77,4 +77,17 @@ public interface UpgradeProtocol { * @return An instance of the HTTP upgrade handler for this protocol */ public InternalHttpUpgradeHandler getInteralUpgradeHandler(Adapter adapter, Request request); + + + /** + * Allows the implementation to examine the request and accept or reject it + * based on what it finds. + * + * @param request The request that included an upgrade header for this + * protocol + * + * @return <code>true</code> if the request is accepted, otherwise + * <code>false</code> + */ + public boolean accept(Request request); } Modified: tomcat/trunk/java/org/apache/coyote/http11/Http11Processor.java URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/coyote/http11/Http11Processor.java?rev=1683096&r1=1683095&r2=1683096&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/coyote/http11/Http11Processor.java (original) +++ tomcat/trunk/java/org/apache/coyote/http11/Http11Processor.java Tue Jun 2 12:58:37 2015 @@ -1035,14 +1035,16 @@ public class Http11Processor extends Abs UpgradeProtocol upgradeProtocol = httpUpgradeProtocols.get(requestedProtocol); if (upgradeProtocol != null) { - // TODO Figure out how to handle request bodies at this - // point. + if (upgradeProtocol.accept(request)) { + // TODO Figure out how to handle request bodies at this + // point. - InternalHttpUpgradeHandler upgradeHandler = - upgradeProtocol.getInteralUpgradeHandler( - getAdapter(), cloneRequest(request)); - action(ActionCode.UPGRADE, upgradeHandler); - return SocketState.UPGRADING; + InternalHttpUpgradeHandler upgradeHandler = + upgradeProtocol.getInteralUpgradeHandler( + getAdapter(), cloneRequest(request)); + action(ActionCode.UPGRADE, upgradeHandler); + return SocketState.UPGRADING; + } } } Modified: tomcat/trunk/java/org/apache/coyote/http2/Http2Protocol.java URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/coyote/http2/Http2Protocol.java?rev=1683096&r1=1683095&r2=1683096&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/coyote/http2/Http2Protocol.java (original) +++ tomcat/trunk/java/org/apache/coyote/http2/Http2Protocol.java Tue Jun 2 12:58:37 2015 @@ -17,6 +17,7 @@ package org.apache.coyote.http2; import java.nio.charset.StandardCharsets; +import java.util.Enumeration; import org.apache.coyote.Adapter; import org.apache.coyote.Processor; @@ -77,6 +78,23 @@ public class Http2Protocol implements Up } + @Override + public boolean accept(Request request) { + // Should only be one HTTP2-Settings header + Enumeration<String> headers = request.getMimeHeaders().values("HTTP2-Settings"); + int count = 0; + while (headers.hasMoreElements()) { + count++; + headers.nextElement(); + } + if (count != 1) { + return false; + } + + return true; + } + + public long getReadTimeout() { return readTimeout; } Modified: tomcat/trunk/test/org/apache/coyote/http2/TestHttp2Section_3_2_1.java URL: http://svn.apache.org/viewvc/tomcat/trunk/test/org/apache/coyote/http2/TestHttp2Section_3_2_1.java?rev=1683096&r1=1683095&r2=1683096&view=diff ============================================================================== --- tomcat/trunk/test/org/apache/coyote/http2/TestHttp2Section_3_2_1.java (original) +++ tomcat/trunk/test/org/apache/coyote/http2/TestHttp2Section_3_2_1.java Tue Jun 2 12:58:37 2015 @@ -25,14 +25,21 @@ public class TestHttp2Section_3_2_1 exte enableHttp2(); configureAndStartWebApplication(); openClientConnection(); - doHttpUpgrade("h2", "", false); + doHttpUpgrade("h2c", "", false); parseHttp11Response(); } - // TODO: Test zero Http2-Settings headers + @Test + public void testMultipleHttp2Settings() throws Exception{ + enableHttp2(); + configureAndStartWebApplication(); + openClientConnection(); + doHttpUpgrade("h2c", Http2TestBase.EMPTY_HTTP2_SETTINGS + Http2TestBase.EMPTY_HTTP2_SETTINGS, + false); + parseHttp11Response(); + } - // TODO: Test multiple Http2-Settings headers // TODO: Test trailing '=' are omitted --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org