Ejemplo n.º 1
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");
        }
Ejemplo n.º 2
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");
        }
Ejemplo n.º 3
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");
        }