示例#1
0
        public void first_request()
        {
            var decoder = new Decoder();
            var encoder = new Encoder(8192);
            var buffer  = new byte[65535];
            var offset  = 0;
            var count   = buffer.Length;
            var headers = new List <IndexedHeader>();

            decoder.HeaderDecoded += (sender, args) => { headers.Add(new IndexedHeader(args.Name, args.Value)); };

            encoder.Encode(":method", "GET", buffer, ref offset, ref count);
            encoder.Encode(":scheme", "http", buffer, ref offset, ref count);
            encoder.Encode(":path", "/", buffer, ref offset, ref count);
            encoder.Encode(":authority", "www.example.com", buffer, ref offset, ref count);
            count  = offset;
            offset = 0;
            decoder.Decode(buffer, ref offset, ref count);

            headers[0].Name.Should().Be(":method");
            headers[0].Value.Should().Be("GET");
            headers[1].Name.Should().Be(":scheme");
            headers[1].Value.Should().Be("http");
            headers[2].Name.Should().Be(":path");
            headers[2].Value.Should().Be("/");
            headers[3].Name.Should().Be(":authority");
            headers[3].Value.Should().Be("www.example.com");
        }
示例#2
0
        public void C43_third_request()
        {
            var hex     = "8287 85bf 4088 25a8 49e9 5ba9 7d7f 8925 a849 e95b b8e8 b4bf ";
            var buffer  = HexToBytes(hex);
            var offset  = 0;
            var count   = buffer.Length;
            var table   = new DynamicTable();
            var headers = new List <IndexedHeader>();

            table.Append(":authority", "www.example.com");
            table.Append("cache-control", "no-cache");

            var decoder = new Decoder(table);

            decoder.HeaderDecoded += (sender, args) => { headers.Add(new IndexedHeader(args.Name, args.Value)); };
            decoder.Decode(buffer, ref offset, ref count);

            headers[0].Name.Should().Be(":method");
            headers[0].Value.Should().Be("GET");
            headers[1].Name.Should().Be(":scheme");
            headers[1].Value.Should().Be("https");
            headers[2].Name.Should().Be(":path");
            headers[2].Value.Should().Be("/index.html");
            headers[3].Name.Should().Be(":authority");
            headers[3].Value.Should().Be("www.example.com");
            headers[4].Name.Should().Be("custom-key");
            headers[4].Value.Should().Be("custom-value");
            table.Get(0).Name.Should().Be("custom-key");
            table.Get(0).Value.Should().Be("custom-value");
            table.Get(1).Name.Should().Be("cache-control");
            table.Get(1).Value.Should().Be("no-cache");
            table.Get(2).Name.Should().Be(":authority");
            table.Get(2).Value.Should().Be("www.example.com");
        }
示例#3
0
        public void C42_second_request()
        {
            var hex     = "8286 84be 5886 a8eb 1064 9cbf";
            var buffer  = HexToBytes(hex);
            var offset  = 0;
            var count   = buffer.Length;
            var table   = new DynamicTable();
            var headers = new List <IndexedHeader>();

            table.Append(":authority", "www.example.com");

            var decoder = new Decoder(table);

            decoder.HeaderDecoded += (sender, args) => { headers.Add(new IndexedHeader(args.Name, args.Value)); };
            decoder.Decode(buffer, ref offset, ref count);

            headers[0].Name.Should().Be(":method");
            headers[0].Value.Should().Be("GET");
            headers[1].Name.Should().Be(":scheme");
            headers[1].Value.Should().Be("http");
            headers[2].Name.Should().Be(":path");
            headers[2].Value.Should().Be("/");
            headers[3].Name.Should().Be(":authority");
            headers[3].Value.Should().Be("www.example.com");
            headers[4].Name.Should().Be("cache-control");
            headers[4].Value.Should().Be("no-cache");
            table.Get(0).Name.Should().Be("cache-control");
            table.Get(0).Value.Should().Be("no-cache");
            table.Get(1).Name.Should().Be(":authority");
            table.Get(1).Value.Should().Be("www.example.com");
        }
示例#4
0
        public void C41_first_request()
        {
            var hex     = "8286 8441 8cf1 e3c2 e5f2 3a6b a0ab 90f4 ff ";
            var buffer  = HexToBytes(hex);
            var offset  = 0;
            var count   = buffer.Length;
            var table   = new DynamicTable();
            var headers = new List <IndexedHeader>();

            var decoder = new Decoder(table);

            decoder.HeaderDecoded += (sender, args) => { headers.Add(new IndexedHeader(args.Name, args.Value)); };
            decoder.Decode(buffer, ref offset, ref count);

            headers[0].Name.Should().Be(":method");
            headers[0].Value.Should().Be("GET");
            headers[1].Name.Should().Be(":scheme");
            headers[1].Value.Should().Be("http");
            headers[2].Name.Should().Be(":path");
            headers[2].Value.Should().Be("/");
            headers[3].Name.Should().Be(":authority");
            headers[3].Value.Should().Be("www.example.com");
            table.Get(0).Name.Should().Be(":authority");
            table.Get(0).Value.Should().Be("www.example.com");
        }
示例#5
0
        public void C21_literal_header_with_indexing()
        {
            var hex    = "400a 6375 7374 6f6d 2d6b 6579 0d63 7573 746f 6d2d 6865 6164 6572";
            var buffer = HexToBytes(hex);
            int offset = 0;
            int count  = buffer.Length;
            var table  = new DynamicTable();

            var decoder = new Decoder(table);

            decoder.Decode(buffer, ref offset, ref count);

            table.Get(0).Name.Should().Be("custom-key");
            table.Get(0).Value.Should().Be("custom-header");
            table.Get(0).Size.Should().Be(55);
        }
示例#6
0
        public void C22_literal_header_without_indexing()
        {
            var           hex    = "040c 2f73 616d 706c 652f 7061 7468";
            var           buffer = HexToBytes(hex);
            var           offset = 0;
            var           count  = buffer.Length;
            var           table  = new DynamicTable();
            IndexedHeader header = null;

            var decoder = new Decoder(table);

            decoder.HeaderDecoded += (sender, args) => { header = new IndexedHeader(args.Name, args.Value); };
            decoder.Decode(buffer, ref offset, ref count);

            table.IsEmpty.Should().BeTrue();
            header.Name.Should().Be(":path");
            header.Value.Should().Be("/sample/path");
        }
示例#7
0
        public void C24_indexed_header_field()
        {
            var             hex    = "82";
            var             buffer = HexToBytes(hex);
            var             offset = 0;
            var             count  = buffer.Length;
            var             table  = new DynamicTable();
            HeaderEventArgs e      = null;

            var decoder = new Decoder(table);

            decoder.HeaderDecoded += (sender, args) => { e = args; };
            decoder.Decode(buffer, ref offset, ref count);

            table.IsEmpty.Should().BeTrue();
            e.Name.Should().Be(":method");
            e.Value.Should().Be("GET");
            e.IsIndexingAllowed.Should().BeTrue();
        }
示例#8
0
        public void C23_literal_header_never_indexed()
        {
            var             hex    = "1008 7061 7373 776f 7264 0673 6563 7265 74";
            var             buffer = HexToBytes(hex);
            var             offset = 0;
            var             count  = buffer.Length;
            var             table  = new DynamicTable();
            HeaderEventArgs e      = null;

            var decoder = new Decoder(table);

            decoder.HeaderDecoded += (sender, args) => { e = args; };
            decoder.Decode(buffer, ref offset, ref count);

            table.IsEmpty.Should().BeTrue();
            e.Name.Should().Be("password");
            e.Value.Should().Be("secret");
            e.IsIndexingAllowed.Should().BeFalse();
        }
示例#9
0
        public void third_request()
        {
            var encoderDynamicTable = new DynamicTable();
            var decoderDynamicTable = new DynamicTable();
            var decoder             = new Decoder(decoderDynamicTable);
            var encoder             = new Encoder(8192, encoderDynamicTable);
            var buffer  = new byte[65535];
            var offset  = 0;
            var count   = buffer.Length;
            var headers = new List <IndexedHeader>();

            decoder.HeaderDecoded += (sender, args) => { headers.Add(new IndexedHeader(args.Name, args.Value)); };
            encoderDynamicTable.Append(":authority", "www.example.com");
            encoderDynamicTable.Append("cache-control", "no-cache");
            decoderDynamicTable.Append(":authority", "www.example.com");
            decoderDynamicTable.Append("cache-control", "no-cache");

            encoder.Encode(":method", "GET", buffer, ref offset, ref count);
            encoder.Encode(":scheme", "https", buffer, ref offset, ref count);
            encoder.Encode(":path", "/index.html", buffer, ref offset, ref count);
            encoder.Encode(":authority", "www.example.com", buffer, ref offset, ref count);
            encoder.Encode("custom-key", "custom-value", buffer, ref offset, ref count);
            var hex = buffer.ToHex();

            count  = offset;
            offset = 0;
            decoder.Decode(buffer, ref offset, ref count);

            buffer[4].Should().Be(0x40, "because authority should be indexed");
            headers[0].Name.Should().Be(":method");
            headers[0].Value.Should().Be("GET");
            headers[1].Name.Should().Be(":scheme");
            headers[1].Value.Should().Be("https");
            headers[2].Name.Should().Be(":path");
            headers[2].Value.Should().Be("/index.html");
            headers[3].Name.Should().Be(":authority");
            headers[3].Value.Should().Be("www.example.com");
            headers[4].Name.Should().Be("custom-key");
            headers[4].Value.Should().Be("custom-value");
        }