Exemple #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");
        }
Exemple #2
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");
        }