Author: markt Date: Tue Jun 23 19:19:56 2015 New Revision: 1687117 URL: http://svn.apache.org/r1687117 Log: Add support for header padding to the tests. Add a simple test for a header frame with padding. Fix a bug in the parser when parsing header frames with padding.
Modified: tomcat/trunk/java/org/apache/coyote/http2/Http2Parser.java tomcat/trunk/test/org/apache/coyote/http2/Http2TestBase.java tomcat/trunk/test/org/apache/coyote/http2/TestHttp2Section_4_1.java tomcat/trunk/test/org/apache/coyote/http2/TestHttp2Section_4_3.java tomcat/trunk/test/org/apache/coyote/http2/TestHttp2Section_5_1.java tomcat/trunk/test/org/apache/coyote/http2/TestHttp2Section_6_2.java Modified: tomcat/trunk/java/org/apache/coyote/http2/Http2Parser.java URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/coyote/http2/Http2Parser.java?rev=1687117&r1=1687116&r2=1687117&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/coyote/http2/Http2Parser.java (original) +++ tomcat/trunk/java/org/apache/coyote/http2/Http2Parser.java Tue Jun 23 19:19:56 2015 @@ -225,6 +225,7 @@ class Http2Parser { } payloadSize -= optionalLen; + payloadSize -= padLength; } boolean endOfHeaders = Flags.isEndOfHeaders(flags); Modified: tomcat/trunk/test/org/apache/coyote/http2/Http2TestBase.java URL: http://svn.apache.org/viewvc/tomcat/trunk/test/org/apache/coyote/http2/Http2TestBase.java?rev=1687117&r1=1687116&r2=1687117&view=diff ============================================================================== --- tomcat/trunk/test/org/apache/coyote/http2/Http2TestBase.java (original) +++ tomcat/trunk/test/org/apache/coyote/http2/Http2TestBase.java Tue Jun 23 19:19:56 2015 @@ -109,10 +109,15 @@ public abstract class Http2TestBase exte protected void sendSimpleGetRequest(int streamId) throws IOException { + sendSimpleGetRequest(streamId, null); + } + + + protected void sendSimpleGetRequest(int streamId, byte[] padding) throws IOException { byte[] frameHeader = new byte[9]; ByteBuffer headersPayload = ByteBuffer.allocate(128); - buildSimpleGetRequest(frameHeader, headersPayload, streamId); + buildSimpleGetRequest(frameHeader, headersPayload, padding, streamId); writeFrame(frameHeader, headersPayload); } @@ -126,24 +131,30 @@ public abstract class Http2TestBase exte } - protected void buildSimpleGetRequest(byte[] frameHeader, ByteBuffer headersPayload, int streamId) { - buildGetRequest(frameHeader, headersPayload, streamId, "/simple"); + protected void buildSimpleGetRequest(byte[] frameHeader, ByteBuffer headersPayload, + byte[] padding, int streamId) { + buildGetRequest(frameHeader, headersPayload, padding, streamId, "/simple"); } protected void buildLargeGetRequest(byte[] frameHeader, ByteBuffer headersPayload, int streamId) { - buildGetRequest(frameHeader, headersPayload, streamId, "/large"); + buildGetRequest(frameHeader, headersPayload, null, streamId, "/large"); } - protected void buildGetRequest(byte[] frameHeader, ByteBuffer headersPayload, int streamId, - String url) { + protected void buildGetRequest(byte[] frameHeader, ByteBuffer headersPayload, byte[] padding, + int streamId, String url) { + if (padding != null) { + headersPayload.put((byte) (0xFF & padding.length)); + } MimeHeaders headers = new MimeHeaders(); headers.addValue(":method").setString("GET"); headers.addValue(":path").setString(url); headers.addValue(":authority").setString("localhost:" + getPort()); hpackEncoder.encode(headers, headersPayload); - + if (padding != null) { + headersPayload.put(padding); + } headersPayload.flip(); ByteUtil.setThreeBytes(frameHeader, 0, headersPayload.limit()); @@ -151,6 +162,9 @@ public abstract class Http2TestBase exte frameHeader[3] = 0x01; // Flags. end of headers (0x04). end of stream (0x01) frameHeader[4] = 0x05; + if (padding != null) { + frameHeader[4] += 0x08; + } // Stream id ByteUtil.set31Bits(frameHeader, 5, streamId); } Modified: tomcat/trunk/test/org/apache/coyote/http2/TestHttp2Section_4_1.java URL: http://svn.apache.org/viewvc/tomcat/trunk/test/org/apache/coyote/http2/TestHttp2Section_4_1.java?rev=1687117&r1=1687116&r2=1687117&view=diff ============================================================================== --- tomcat/trunk/test/org/apache/coyote/http2/TestHttp2Section_4_1.java (original) +++ tomcat/trunk/test/org/apache/coyote/http2/TestHttp2Section_4_1.java Tue Jun 23 19:19:56 2015 @@ -58,7 +58,7 @@ public class TestHttp2Section_4_1 extend // Build the simple request byte[] frameHeader = new byte[9]; ByteBuffer headersPayload = ByteBuffer.allocate(128); - buildSimpleGetRequest(frameHeader, headersPayload, 3); + buildSimpleGetRequest(frameHeader, headersPayload, null, 3); // Tweak the header to set the reserved bit frameHeader[5] = (byte) (frameHeader[5] | 0x80); Modified: tomcat/trunk/test/org/apache/coyote/http2/TestHttp2Section_4_3.java URL: http://svn.apache.org/viewvc/tomcat/trunk/test/org/apache/coyote/http2/TestHttp2Section_4_3.java?rev=1687117&r1=1687116&r2=1687117&view=diff ============================================================================== --- tomcat/trunk/test/org/apache/coyote/http2/TestHttp2Section_4_3.java (original) +++ tomcat/trunk/test/org/apache/coyote/http2/TestHttp2Section_4_3.java Tue Jun 23 19:19:56 2015 @@ -38,7 +38,7 @@ public class TestHttp2Section_4_3 extend // Build the simple request byte[] frameHeader = new byte[9]; ByteBuffer headersPayload = ByteBuffer.allocate(128); - buildSimpleGetRequest(frameHeader, headersPayload, 3); + buildSimpleGetRequest(frameHeader, headersPayload, null, 3); // Try and corrupt the headerPayload headersPayload.put(0, (byte) (headersPayload.get(0) + 128)); Modified: tomcat/trunk/test/org/apache/coyote/http2/TestHttp2Section_5_1.java URL: http://svn.apache.org/viewvc/tomcat/trunk/test/org/apache/coyote/http2/TestHttp2Section_5_1.java?rev=1687117&r1=1687116&r2=1687117&view=diff ============================================================================== --- tomcat/trunk/test/org/apache/coyote/http2/TestHttp2Section_5_1.java (original) +++ tomcat/trunk/test/org/apache/coyote/http2/TestHttp2Section_5_1.java Tue Jun 23 19:19:56 2015 @@ -87,7 +87,7 @@ public class TestHttp2Section_5_1 extend // Build the simple request byte[] frameHeader = new byte[9]; ByteBuffer headersPayload = ByteBuffer.allocate(128); - buildSimpleGetRequest(frameHeader, headersPayload, 3); + buildSimpleGetRequest(frameHeader, headersPayload, null, 3); // Remove the end of stream and end of headers flags frameHeader[4] = 0; @@ -155,7 +155,7 @@ public class TestHttp2Section_5_1 extend // Build the simple request on an old stream byte[] frameHeader = new byte[9]; ByteBuffer headersPayload = ByteBuffer.allocate(128); - buildSimpleGetRequest(frameHeader, headersPayload, 3); + buildSimpleGetRequest(frameHeader, headersPayload, null, 3); os.write(frameHeader); os.flush(); Modified: tomcat/trunk/test/org/apache/coyote/http2/TestHttp2Section_6_2.java URL: http://svn.apache.org/viewvc/tomcat/trunk/test/org/apache/coyote/http2/TestHttp2Section_6_2.java?rev=1687117&r1=1687116&r2=1687117&view=diff ============================================================================== --- tomcat/trunk/test/org/apache/coyote/http2/TestHttp2Section_6_2.java (original) +++ tomcat/trunk/test/org/apache/coyote/http2/TestHttp2Section_6_2.java Tue Jun 23 19:19:56 2015 @@ -31,7 +31,7 @@ import org.junit.Test; public class TestHttp2Section_6_2 extends Http2TestBase { @Test - public void testHeaderOnStreamZero() throws Exception { + public void testHeaderFrameOnStreamZero() throws Exception { // HTTP2 upgrade http2Connect(); @@ -47,4 +47,23 @@ public class TestHttp2Section_6_2 extend Assert.assertTrue(output.getTrace(), output.getTrace().startsWith( "0-Goaway-[1]-[" + Http2Error.PROTOCOL_ERROR.getCode() + "]-[")); } + + + @Test + public void testHeaderFrameWithPadding() throws Exception { + http2Connect(); + + byte[] padding= new byte[8]; + + sendSimpleGetRequest(3, padding); + readSimpleGetResponse(); + Assert.assertEquals(getSimpleResponseTrace(3), output.getTrace()); + output.clearTrace(); + } + + // with non-zero padding + + // too much padding + + // zero length padding } --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org