예제 #1
0
        public override void ParsePayload(byte[] payloadData, FrameHeader frameHeader)
        {
            EndStream  = (frameHeader.Flags & 0x1) == 0x1;
            EndHeaders = (frameHeader.Flags & 0x4) == 0x4;
            Priority   = (frameHeader.Flags & 0x20) == 0x20;
            Padded     = (frameHeader.Flags & 0x8) == 0x8;

            var index = 0;

            if (Padded)
            {
                // Get pad length (1 byte)
                padLength = (ushort)payloadData [index];
                index++;
            }
            else
            {
                padLength = 0;
            }

            if (Priority)
            {
                // Get Dependency Stream Id
                // we need to turn the stream id into a uint
                var frameStreamIdData = new byte[4];
                Array.Copy(payloadData, index, frameStreamIdData, 0, 4);
                StreamDependency = Util.ConvertFromUInt31(frameStreamIdData.EnsureBigEndian());

                // Get the weight
                weight = (ushort)payloadData [index + 4];

                // Advance the index
                index += 5;
            }


            // create an array for the header data to read
            // it will be the payload length, minus the pad length value, weight, stream id, and padding
            var headerData = new byte[payloadData.Length - (index + padLength)];

            Array.Copy(payloadData, index, headerData, 0, headerData.Length);

            // Decode Header Block Fragments
            var hpackDecoder = new HPack.Decoder(8192, 4096);

            using (var binReader = new BinaryReader(new MemoryStream(headerData))) {
                hpackDecoder.Decode(binReader, (name, value, sensitive) =>
                                    Headers.Add(
                                        System.Text.Encoding.ASCII.GetString(name),
                                        System.Text.Encoding.ASCII.GetString(value)));

                hpackDecoder.EndHeaderBlock(); // this must be called to finalize the decoding process.
            }

            // Advance the index
            index += headerData.Length;

            // Don't care about padding
        }
예제 #2
0
        public override void ParsePayload(byte[] payloadData, FrameHeader frameHeader)
        {
            EndHeaders = (frameHeader.Flags & 0x4) == 0x4;

            // Decode Header Block Fragments
            var hpackDecoder = new HPack.Decoder(8192, 4096);

            using (var binReader = new BinaryReader(new MemoryStream(payloadData))) {
                hpackDecoder.Decode(binReader, (name, value, sensitive) =>
                                    Headers.Add(
                                        System.Text.Encoding.ASCII.GetString(name),
                                        System.Text.Encoding.ASCII.GetString(value)));

                hpackDecoder.EndHeaderBlock(); // this must be called to finalize the decoding process.
            }
        }
예제 #3
0
        public static NameValueCollection UnpackHeaders(byte[] data, int maxHeaderSize, int maxHeaderTableSize)
        {
            var headers = new NameValueCollection();

            // Decode Header Block Fragments
            var hpackDecoder = new HPack.Decoder(maxHeaderSize, maxHeaderTableSize);

            using (var binReader = new BinaryReader(new MemoryStream(data))) {
                hpackDecoder.Decode(binReader, (name, value, sensitive) =>
                                    headers.Add(
                                        System.Text.Encoding.ASCII.GetString(name),
                                        System.Text.Encoding.ASCII.GetString(value)));

                hpackDecoder.EndHeaderBlock(); // this must be called to finalize the decoding process.
            }

            return(headers);
        }
예제 #4
0
        public static NameValueCollection UnpackHeaders (byte[] data, int maxHeaderSize, int maxHeaderTableSize)
        {
            var headers = new NameValueCollection ();

            // Decode Header Block Fragments
            var hpackDecoder = new HPack.Decoder (maxHeaderSize, maxHeaderTableSize);
            using(var binReader = new BinaryReader (new MemoryStream (data))) {

                hpackDecoder.Decode(binReader, (name, value, sensitive) => 
                    headers.Add (
                        System.Text.Encoding.ASCII.GetString (name), 
                        System.Text.Encoding.ASCII.GetString (value)));

                hpackDecoder.EndHeaderBlock(); // this must be called to finalize the decoding process.
            }

            return headers;
        }
예제 #5
0
        public override void ParsePayload(byte[] payloadData, FrameHeader frameHeader)
        {
            EndHeaders = (frameHeader.Flags & 0x4) == 0x4;

            // Decode Header Block Fragments
            var hpackDecoder = new HPack.Decoder (8192, 4096);
            using(var binReader = new BinaryReader (new MemoryStream (payloadData))) {

                hpackDecoder.Decode(binReader, (name, value, sensitive) =>
                    Headers.Add (
                        System.Text.Encoding.ASCII.GetString (name),
                        System.Text.Encoding.ASCII.GetString (value)));

                hpackDecoder.EndHeaderBlock(); // this must be called to finalize the decoding process.
            }
        }