Exemplo n.º 1
0
        internal static HpackDecoder NewTestDecoder(long maxHeaderListSize, long maxHeaderTableSize)
        {
            HpackDecoder hpackDecoder = new HpackDecoder(maxHeaderListSize);

            hpackDecoder.SetMaxHeaderTableSize(maxHeaderTableSize);
            return(hpackDecoder);
        }
Exemplo n.º 2
0
        public void TestDecodeULE128IntMax()
        {
            byte[] bytes = { (byte)0xFF, (byte)0xFF, (byte)0xFF, (byte)0xFF, (byte)0x07 };
            var    input = Unpooled.WrappedBuffer(bytes);

            try
            {
                Assert.Equal(int.MaxValue, HpackDecoder.DecodeULE128(input, 0));
            }
            finally
            {
                input.Release();
            }
        }
Exemplo n.º 3
0
        public void TestDecodeULE128LongMax()
        {
            byte[]      bytes = { (byte)0xFF, (byte)0xFF, (byte)0xFF, (byte)0xFF, (byte)0xFF, (byte)0xFF, (byte)0xFF,
                                  (byte)0xFF,      (byte)0x7F };
            IByteBuffer input = Unpooled.WrappedBuffer(bytes);

            try
            {
                Assert.Equal(long.MaxValue, HpackDecoder.DecodeULE128(input, 0L));
            }
            finally
            {
                input.Release();
            }
        }
Exemplo n.º 4
0
        private static List <HpackHeaderField> Decode(HpackDecoder hpackDecoder, byte[] expected)
        {
            var input = Unpooled.WrappedBuffer(expected);

            try
            {
                List <HpackHeaderField> headers  = new List <HpackHeaderField>();
                TestHeaderListener      listener = new TestHeaderListener(headers);
                hpackDecoder.Decode(0, input, listener, true);
                return(headers);
            }
            finally
            {
                input.Release();
            }
        }
Exemplo n.º 5
0
 public void TestDecodeULE128IntOverflow2()
 {
     Assert.Throws <Http2Exception>(() =>
     {
         byte[] bytes      = { (byte)0xFF, (byte)0xFF, (byte)0xFF, (byte)0xFF, (byte)0x08 };
         IByteBuffer input = Unpooled.WrappedBuffer(bytes);
         int readerIndex   = input.ReaderIndex;
         try
         {
             HpackDecoder.DecodeULE128(input, 0);
         }
         finally
         {
             Assert.Equal(readerIndex, input.ReaderIndex);
             input.Release();
         }
     });
 }
Exemplo n.º 6
0
        internal void TestDecompress()
        {
            HpackDecoder hpackDecoder = this.CreateDecoder();

            foreach (HeaderBlock headerBlock in this.headerBlocks)
            {
                List <HpackHeaderField> actualHeaders = Decode(hpackDecoder, headerBlock.encodedBytes);

                List <HpackHeaderField> expectedHeaders = new List <HpackHeaderField>();
                foreach (HpackHeaderField h in headerBlock.GetHeaders())
                {
                    expectedHeaders.Add(new HpackHeaderField(h._name, h._value));
                }

                if (!HeadersEqual(expectedHeaders, actualHeaders))
                {
                    throw new Exception(
                              "\nEXPECTED:\n" + expectedHeaders +
                              "\nACTUAL:\n" + actualHeaders);
                }

                List <HpackHeaderField> actualDynamicTable = new List <HpackHeaderField>();
                for (int index = 0; index < hpackDecoder.Length(); index++)
                {
                    actualDynamicTable.Add(hpackDecoder.GetHeaderField(index));
                }

                List <HpackHeaderField> expectedDynamicTable = headerBlock.GetDynamicTable();

                if (!HeadersEqual(expectedDynamicTable, actualDynamicTable))
                {
                    throw new Exception(
                              "\nEXPECTED DYNAMIC TABLE:\n" + expectedDynamicTable +
                              "\nACTUAL DYNAMIC TABLE:\n" + actualDynamicTable);
                }

                if (headerBlock.GetTableSize() != hpackDecoder.Size())
                {
                    throw new Exception(
                              "\nEXPECTED TABLE SIZE: " + headerBlock.GetTableSize() +
                              "\n ACTUAL TABLE SIZE : " + hpackDecoder.Size());
                }
            }
        }
Exemplo n.º 7
0
 public HpackDecoderTest()
 {
     this.hpackDecoder = new HpackDecoder(8192);
     this.mockHeaders  = new Mock <IHttp2Headers>(MockBehavior.Default);
 }
Exemplo n.º 8
0
 public HpackEncoderTest()
 {
     hpackEncoder = new HpackEncoder();
     hpackDecoder = new HpackDecoder(Http2CodecUtil.DefaultHeaderListSize);
     mockHeaders  = new Mock <IHttp2Headers>(MockBehavior.Strict);
 }