SpdyHeaderBlockRawDecoder extends SpdyHeaderBlockDecoder { @Override void decode(ByteBufAllocator alloc, ByteBuf headerBlock, SpdyHeadersFrame frame) throws Exception { if (headerBlock == null) { throw new NullPointerException("headerBlock"); } if (frame == null) { throw new NullPointerException("frame"); } if (cumulation == null) { decodeHeaderBlock(headerBlock, frame); if (headerBlock.isReadable()) { cumulation = alloc.buffer(headerBlock.readableBytes()); cumulation.writeBytes(headerBlock); } } else { cumulation.writeBytes(headerBlock); decodeHeaderBlock(cumulation, frame); if (cumulation.isReadable()) { cumulation.discardReadBytes(); } else { releaseBuffer(); } } } SpdyHeaderBlockRawDecoder(SpdyVersion spdyVersion, int maxHeaderSize);   }
@Test public void testNegativeNameValuePairs() throws Exception { ByteBuf headerBlock = Unpooled.buffer(4); headerBlock.writeInt(-1); decoder.decode(ByteBufAllocator.DEFAULT, headerBlock, frame); assertFalse(headerBlock.isReadable()); assertTrue(frame.isInvalid()); assertEquals(0, frame.headers().names().size()); headerBlock.release(); }
@Test public void testZeroNameLength() throws Exception { ByteBuf headerBlock = Unpooled.buffer(8); headerBlock.writeInt(1); headerBlock.writeInt(0); decoder.decode(ByteBufAllocator.DEFAULT, headerBlock, frame); assertFalse(headerBlock.isReadable()); assertTrue(frame.isInvalid()); assertEquals(0, frame.headers().names().size()); headerBlock.release(); }
@Test public void testNegativeNameLength() throws Exception { ByteBuf headerBlock = Unpooled.buffer(8); headerBlock.writeInt(1); headerBlock.writeInt(-1); decoder.decode(ByteBufAllocator.DEFAULT, headerBlock, frame); assertFalse(headerBlock.isReadable()); assertTrue(frame.isInvalid()); assertEquals(0, frame.headers().names().size()); headerBlock.release(); }
@Test public void testIllegalNameOnlyNull() throws Exception { ByteBuf headerBlock = Unpooled.buffer(18); headerBlock.writeInt(1); headerBlock.writeInt(1); headerBlock.writeByte(0); headerBlock.writeInt(5); headerBlock.writeBytes(valueBytes); decoder.decode(ByteBufAllocator.DEFAULT, headerBlock, frame); assertFalse(headerBlock.isReadable()); assertTrue(frame.isInvalid()); assertEquals(0, frame.headers().names().size()); headerBlock.release(); }
@Test public void testNegativeValueLength() throws Exception { ByteBuf headerBlock = Unpooled.buffer(16); headerBlock.writeInt(1); headerBlock.writeInt(4); headerBlock.writeBytes(nameBytes); headerBlock.writeInt(-1); decoder.decode(ByteBufAllocator.DEFAULT, headerBlock, frame); assertFalse(headerBlock.isReadable()); assertTrue(frame.isInvalid()); assertEquals(0, frame.headers().names().size()); headerBlock.release(); }
@Test public void testIllegalValueOnlyNull() throws Exception { ByteBuf headerBlock = Unpooled.buffer(17); headerBlock.writeInt(1); headerBlock.writeInt(4); headerBlock.writeBytes(nameBytes); headerBlock.writeInt(1); headerBlock.writeByte(0); decoder.decode(ByteBufAllocator.DEFAULT, headerBlock, frame); assertFalse(headerBlock.isReadable()); assertTrue(frame.isInvalid()); assertEquals(0, frame.headers().names().size()); headerBlock.release(); }
@Test public void testIllegalValueStartsWithNull() throws Exception { ByteBuf headerBlock = Unpooled.buffer(22); headerBlock.writeInt(1); headerBlock.writeInt(4); headerBlock.writeBytes(nameBytes); headerBlock.writeInt(6); headerBlock.writeByte(0); headerBlock.writeBytes(valueBytes); decoder.decode(ByteBufAllocator.DEFAULT, headerBlock, frame); assertFalse(headerBlock.isReadable()); assertTrue(frame.isInvalid()); assertEquals(0, frame.headers().names().size()); headerBlock.release(); }
@Test public void testIllegalValueEndsWithNull() throws Exception { ByteBuf headerBlock = Unpooled.buffer(22); headerBlock.writeInt(1); headerBlock.writeInt(4); headerBlock.writeBytes(nameBytes); headerBlock.writeInt(6); headerBlock.writeBytes(valueBytes); headerBlock.writeByte(0); decoder.decode(ByteBufAllocator.DEFAULT, headerBlock, frame); assertFalse(headerBlock.isReadable()); assertTrue(frame.isInvalid()); assertEquals(0, frame.headers().names().size()); headerBlock.release(); }
@Test public void testMultipleValuesEndsWithNull() throws Exception { ByteBuf headerBlock = Unpooled.buffer(28); headerBlock.writeInt(1); headerBlock.writeInt(4); headerBlock.writeBytes(nameBytes); headerBlock.writeInt(12); headerBlock.writeBytes(valueBytes); headerBlock.writeByte(0); headerBlock.writeBytes(valueBytes); headerBlock.writeByte(0); decoder.decode(ByteBufAllocator.DEFAULT, headerBlock, frame); assertFalse(headerBlock.isReadable()); assertTrue(frame.isInvalid()); assertEquals(1, frame.headers().names().size()); assertTrue(frame.headers().contains(name)); assertEquals(1, frame.headers().getAll(name).size()); assertEquals(value, frame.headers().get(name)); headerBlock.release(); }
@Test public void testMultipleNames() throws Exception { ByteBuf headerBlock = Unpooled.buffer(38); headerBlock.writeInt(2); headerBlock.writeInt(4); headerBlock.writeBytes(nameBytes); headerBlock.writeInt(5); headerBlock.writeBytes(valueBytes); headerBlock.writeInt(4); headerBlock.writeBytes(nameBytes); headerBlock.writeInt(5); headerBlock.writeBytes(valueBytes); decoder.decode(ByteBufAllocator.DEFAULT, headerBlock, frame); assertFalse(headerBlock.isReadable()); assertTrue(frame.isInvalid()); assertEquals(1, frame.headers().names().size()); assertTrue(frame.headers().contains(name)); assertEquals(1, frame.headers().getAll(name).size()); assertEquals(value, frame.headers().get(name)); headerBlock.release(); }
@Test public void testExtraData() throws Exception { ByteBuf headerBlock = Unpooled.buffer(22); headerBlock.writeInt(1); headerBlock.writeInt(4); headerBlock.writeBytes(nameBytes); headerBlock.writeInt(5); headerBlock.writeBytes(valueBytes); headerBlock.writeByte(0); decoder.decode(ByteBufAllocator.DEFAULT, headerBlock, frame); assertFalse(headerBlock.isReadable()); assertTrue(frame.isInvalid()); assertEquals(1, frame.headers().names().size()); assertTrue(frame.headers().contains(name)); assertEquals(1, frame.headers().getAll(name).size()); assertEquals(value, frame.headers().get(name)); headerBlock.release(); }