예제 #1
0
        public async Task HeaderParse(string hex, string expectedHeader, string expectedTable)
        {
            using (var memoryPool = new MemoryPool())
                using (var channelFactory = new ChannelFactory(memoryPool))
                {
                    var readerTable = default(HeaderTable);
                    var writerTable = default(HeaderTable);
                    try
                    {
                        var readable = HexToBuffer(ref hex);
                        var header   = Hpack.ReadHeader(ref readable, ref readerTable, memoryPool);
                        Assert.Equal(expectedHeader, header.ToString());
                        Assert.Equal(expectedTable, readerTable.ToString());

                        var channel = channelFactory.CreateChannel();

                        var wb = channel.Alloc();
                        Hpack.WriteHeader(wb, header, ref writerTable, memoryPool);
                        Assert.Equal(hex, ToHex(wb));
                        await wb.FlushAsync();
                    }
                    finally
                    {
                        readerTable.Dispose();
                        writerTable.Dispose();
                    }
                }
        }
예제 #2
0
        public async Task C_1_123(string hex, int n, int expected, byte preamble)
        {
            var readable = HexToBuffer(ref hex);

            Assert.Equal((ulong)expected, Hpack.ReadUInt64(ref readable, n));

            using (var channelFactory = new ChannelFactory())
            {
                var channel = channelFactory.CreateChannel();
                var wb      = channel.Alloc();
                Hpack.WriteUInt32(wb, (uint)expected, preamble, n);
                Assert.Equal(hex, ToHex(wb));
                await wb.FlushAsync();
            }
        }
예제 #3
0
        public async Task BasicStringParse(string hex, string expected, bool huffman)
        {
            var  readable = HexToBuffer(ref hex);
            bool isCompressed;

            Assert.Equal(expected, Hpack.ReadString(ref readable, out isCompressed));
            Assert.Equal(huffman, isCompressed);

            using (var channelFactory = new ChannelFactory())
            {
                var channel = channelFactory.CreateChannel();
                var wb      = channel.Alloc();
                Hpack.WriteNameString(wb, expected, huffman ? HeaderOptions.NameCompressionOn : HeaderOptions.NameCompressionOff);
                Assert.Equal(hex, ToHex(wb));
                await wb.FlushAsync();
            }
        }
예제 #4
0
        public async Task C61_C62_C63()
        {
            using (var memoryPool = new MemoryPool())
                using (var channelFactory = new ChannelFactory(memoryPool))
                {
                    var channel     = channelFactory.CreateChannel();
                    var readerTable = new HeaderTable(256);
                    var writerTable = new HeaderTable(256);
                    try
                    {
                        var hex        = @"
4882 6402 5885 aec3 771a 4b61 96d0 7abe
9410 54d4 44a8 2005 9504 0b81 66e0 82a6
2d1b ff6e 919d 29ad 1718 63c7 8f0b 97c8
e9ae 82ae 43d3";
                        var readable   = HexToBuffer(ref hex);
                        var httpHeader = Hpack.ParseHttpHeader(ref readable, ref readerTable, memoryPool);
                        Assert.Equal(
                            @":status: 302
cache-control: private
date: Mon, 21 Oct 2013 20:13:21 GMT
location: https://www.example.com
", httpHeader.ToString());
                        Assert.Equal(
                            @"[1] (s = 63) location: https://www.example.com
[2] (s = 65) date: Mon, 21 Oct 2013 20:13:21 GMT
[3] (s = 52) cache-control: private
[4] (s = 42) :status: 302
Table size: 222
", readerTable.ToString());

                        var wb = channel.Alloc();
                        Hpack.WriteHttpHeader(wb, httpHeader, ref writerTable, memoryPool);
                        Assert.Equal(hex, ToHex(wb));
                        await wb.FlushAsync();

                        Assert.Equal(
                            @"[1] (s = 63) location: https://www.example.com
[2] (s = 65) date: Mon, 21 Oct 2013 20:13:21 GMT
[3] (s = 52) cache-control: private
[4] (s = 42) :status: 302
Table size: 222
", writerTable.ToString());

                        hex        = "4883 640e ffc1 c0bf";
                        readable   = HexToBuffer(ref hex);
                        httpHeader = Hpack.ParseHttpHeader(ref readable, ref readerTable, memoryPool);
                        Assert.Equal(
                            @":status: 307
cache-control: private
date: Mon, 21 Oct 2013 20:13:21 GMT
location: https://www.example.com
", httpHeader.ToString());
                        Assert.Equal(
                            @"[1] (s = 42) :status: 307
[2] (s = 63) location: https://www.example.com
[3] (s = 65) date: Mon, 21 Oct 2013 20:13:21 GMT
[4] (s = 52) cache-control: private
Table size: 222
", readerTable.ToString());

                        wb = channel.Alloc();
                        Hpack.WriteHttpHeader(wb, httpHeader, ref writerTable, memoryPool);
                        Assert.Equal(hex, ToHex(wb));
                        await wb.FlushAsync();

                        Assert.Equal(
                            @"[1] (s = 42) :status: 307
[2] (s = 63) location: https://www.example.com
[3] (s = 65) date: Mon, 21 Oct 2013 20:13:21 GMT
[4] (s = 52) cache-control: private
Table size: 222
", writerTable.ToString());

                        hex        = @"
88c1 6196 d07a be94 1054 d444 a820 0595
040b 8166 e084 a62d 1bff c05a 839b d9ab
77ad 94e7 821d d7f2 e6c7 b335 dfdf cd5b
3960 d5af 2708 7f36 72c1 ab27 0fb5 291f
9587 3160 65c0 03ed 4ee5 b106 3d50 07";
                        readable   = HexToBuffer(ref hex);
                        httpHeader = Hpack.ParseHttpHeader(ref readable, ref readerTable, memoryPool);
                        Assert.Equal(
                            @":status: 200
cache-control: private
date: Mon, 21 Oct 2013 20:13:22 GMT
location: https://www.example.com
content-encoding: gzip
set-cookie: foo=ASDJKHQKBZXOQWEOPIUAXQWEOIU; max-age=3600; version=1
", httpHeader.ToString());
                        Assert.Equal(
                            @"[1] (s = 98) set-cookie: foo=ASDJKHQKBZXOQWEOPIUAXQWEOIU; max-age=3600; version=1
[2] (s = 52) content-encoding: gzip
[3] (s = 65) date: Mon, 21 Oct 2013 20:13:22 GMT
Table size: 215
", readerTable.ToString());

                        wb = channel.Alloc();
                        Hpack.WriteHttpHeader(wb, httpHeader, ref writerTable, memoryPool);
                        Assert.Equal(hex, ToHex(wb));
                        await wb.FlushAsync();

                        Assert.Equal(
                            @"[1] (s = 98) set-cookie: foo=ASDJKHQKBZXOQWEOPIUAXQWEOIU; max-age=3600; version=1
[2] (s = 52) content-encoding: gzip
[3] (s = 65) date: Mon, 21 Oct 2013 20:13:22 GMT
Table size: 215
", writerTable.ToString());
                    }
                    finally
                    {
                        readerTable.Dispose();
                        writerTable.Dispose();
                    }
                }
        }
예제 #5
0
        public async Task C51_C52_C53()
        {
            using (var memoryPool = new MemoryPool())
                using (var channelFactory = new ChannelFactory(memoryPool))
                {
                    var channel     = channelFactory.CreateChannel();
                    var readerTable = new HeaderTable(256);
                    var writerTable = new HeaderTable(256);
                    try
                    {
                        var hex        = @"
4803 3330 3258 0770 7269 7661 7465 611d
4d6f 6e2c 2032 3120 4f63 7420 3230 3133
2032 303a 3133 3a32 3120 474d 546e 1768
7474 7073 3a2f 2f77 7777 2e65 7861 6d70
6c65 2e63 6f6d";
                        var readable   = HexToBuffer(ref hex);
                        var httpHeader = Hpack.ParseHttpHeader(ref readable, ref readerTable, memoryPool);
                        Assert.Equal(
                            @":status: 302
cache-control: private
date: Mon, 21 Oct 2013 20:13:21 GMT
location: https://www.example.com
", httpHeader.ToString());
                        Assert.Equal(
                            @"[1] (s = 63) location: https://www.example.com
[2] (s = 65) date: Mon, 21 Oct 2013 20:13:21 GMT
[3] (s = 52) cache-control: private
[4] (s = 42) :status: 302
Table size: 222
", readerTable.ToString());

                        var wb = channel.Alloc();
                        Hpack.WriteHttpHeader(wb, httpHeader, ref writerTable, memoryPool);
                        Assert.Equal(hex, ToHex(wb));
                        await wb.FlushAsync();

                        Assert.Equal(
                            @"[1] (s = 63) location: https://www.example.com
[2] (s = 65) date: Mon, 21 Oct 2013 20:13:21 GMT
[3] (s = 52) cache-control: private
[4] (s = 42) :status: 302
Table size: 222
", writerTable.ToString());

                        hex        = "4803 3330 37c1 c0bf";
                        readable   = HexToBuffer(ref hex);
                        httpHeader = Hpack.ParseHttpHeader(ref readable, ref readerTable, memoryPool);
                        Assert.Equal(
                            @":status: 307
cache-control: private
date: Mon, 21 Oct 2013 20:13:21 GMT
location: https://www.example.com
", httpHeader.ToString());
                        Assert.Equal(
                            @"[1] (s = 42) :status: 307
[2] (s = 63) location: https://www.example.com
[3] (s = 65) date: Mon, 21 Oct 2013 20:13:21 GMT
[4] (s = 52) cache-control: private
Table size: 222
", readerTable.ToString());

                        wb = channel.Alloc();
                        Hpack.WriteHttpHeader(wb, httpHeader, ref writerTable, memoryPool);
                        Assert.Equal(hex, ToHex(wb));
                        await wb.FlushAsync();

                        Assert.Equal(
                            @"[1] (s = 42) :status: 307
[2] (s = 63) location: https://www.example.com
[3] (s = 65) date: Mon, 21 Oct 2013 20:13:21 GMT
[4] (s = 52) cache-control: private
Table size: 222
", writerTable.ToString());

                        hex        = @"
88c1 611d 4d6f 6e2c 2032 3120 4f63 7420
3230 3133 2032 303a 3133 3a32 3220 474d
54c0 5a04 677a 6970 7738 666f 6f3d 4153
444a 4b48 514b 425a 584f 5157 454f 5049
5541 5851 5745 4f49 553b 206d 6178 2d61
6765 3d33 3630 303b 2076 6572 7369 6f6e
3d31";
                        readable   = HexToBuffer(ref hex);
                        httpHeader = Hpack.ParseHttpHeader(ref readable, ref readerTable, memoryPool);
                        Assert.Equal(
                            @":status: 200
cache-control: private
date: Mon, 21 Oct 2013 20:13:22 GMT
location: https://www.example.com
content-encoding: gzip
set-cookie: foo=ASDJKHQKBZXOQWEOPIUAXQWEOIU; max-age=3600; version=1
", httpHeader.ToString());
                        Assert.Equal(
                            @"[1] (s = 98) set-cookie: foo=ASDJKHQKBZXOQWEOPIUAXQWEOIU; max-age=3600; version=1
[2] (s = 52) content-encoding: gzip
[3] (s = 65) date: Mon, 21 Oct 2013 20:13:22 GMT
Table size: 215
", readerTable.ToString());

                        wb = channel.Alloc();
                        Hpack.WriteHttpHeader(wb, httpHeader, ref writerTable, memoryPool);
                        Assert.Equal(hex, ToHex(wb));
                        await wb.FlushAsync();

                        Assert.Equal(
                            @"[1] (s = 98) set-cookie: foo=ASDJKHQKBZXOQWEOPIUAXQWEOIU; max-age=3600; version=1
[2] (s = 52) content-encoding: gzip
[3] (s = 65) date: Mon, 21 Oct 2013 20:13:22 GMT
Table size: 215
", writerTable.ToString());
                    }
                    finally
                    {
                        readerTable.Dispose();
                        writerTable.Dispose();
                    }
                }
        }
예제 #6
0
        public async Task C41_C42_C43()
        {
            using (var memoryPool = new MemoryPool())
                using (var channelFactory = new ChannelFactory(memoryPool))
                {
                    var channel     = channelFactory.CreateChannel();
                    var readerTable = default(HeaderTable);
                    var writerTable = default(HeaderTable);
                    try
                    {
                        var hex        = "8286 8441 8cf1 e3c2 e5f2 3a6b a0ab 90f4 ff";
                        var readable   = HexToBuffer(ref hex);
                        var httpHeader = Hpack.ParseHttpHeader(ref readable, ref readerTable, memoryPool);
                        Assert.Equal(
                            @":method: GET
:scheme: http
:path: /
:authority: www.example.com
", httpHeader.ToString());
                        Assert.Equal(
                            @"[1] (s = 57) :authority: www.example.com
Table size: 57
", readerTable.ToString());
                        var wb = channel.Alloc();
                        Hpack.WriteHttpHeader(wb, httpHeader, ref writerTable, memoryPool);
                        Assert.Equal(hex, ToHex(wb));
                        await wb.FlushAsync();

                        Assert.Equal(
                            @"[1] (s = 57) :authority: www.example.com
Table size: 57
", writerTable.ToString());

                        hex        = "8286 84be 5886 a8eb 1064 9cbf";
                        readable   = HexToBuffer(ref hex);
                        httpHeader = Hpack.ParseHttpHeader(ref readable, ref readerTable, memoryPool);
                        Assert.Equal(
                            @":method: GET
:scheme: http
:path: /
:authority: www.example.com
cache-control: no-cache
", httpHeader.ToString());
                        Assert.Equal(
                            @"[1] (s = 53) cache-control: no-cache
[2] (s = 57) :authority: www.example.com
Table size: 110
", readerTable.ToString());

                        wb = channel.Alloc();
                        Hpack.WriteHttpHeader(wb, httpHeader, ref writerTable, memoryPool);
                        Assert.Equal(hex, ToHex(wb));
                        await wb.FlushAsync();

                        Assert.Equal(
                            @"[1] (s = 53) cache-control: no-cache
[2] (s = 57) :authority: www.example.com
Table size: 110
", writerTable.ToString());

                        hex        = "8287 85bf 4088 25a8 49e9 5ba9 7d7f 8925 a849 e95b b8e8 b4bf";
                        readable   = HexToBuffer(ref hex);
                        httpHeader = Hpack.ParseHttpHeader(ref readable, ref readerTable, memoryPool);
                        Assert.Equal(
                            @":method: GET
:scheme: https
:path: /index.html
:authority: www.example.com
custom-key: custom-value
", httpHeader.ToString());
                        Assert.Equal(
                            @"[1] (s = 54) custom-key: custom-value
[2] (s = 53) cache-control: no-cache
[3] (s = 57) :authority: www.example.com
Table size: 164
", readerTable.ToString());

                        wb = channel.Alloc();
                        Hpack.WriteHttpHeader(wb, httpHeader, ref writerTable, memoryPool);
                        Assert.Equal(hex, ToHex(wb));
                        await wb.FlushAsync();

                        Assert.Equal(
                            @"[1] (s = 54) custom-key: custom-value
[2] (s = 53) cache-control: no-cache
[3] (s = 57) :authority: www.example.com
Table size: 164
", writerTable.ToString());
                    }
                    finally
                    {
                        readerTable.Dispose();
                        writerTable.Dispose();
                    }
                }
        }
예제 #7
0
        public async Task C31_C32_C33()
        {
            using (var memoryPool = new MemoryPool())
                using (var channelFactory = new ChannelFactory(memoryPool))
                {
                    var channel     = channelFactory.CreateChannel();
                    var readerTable = default(HeaderTable);
                    var writerTable = default(HeaderTable);
                    try
                    {
                        var hex        = "8286 8441 0f77 7777 2e65 7861 6d70 6c65 2e63 6f6d";
                        var readable   = HexToBuffer(ref hex);
                        var httpHeader = Hpack.ParseHttpHeader(ref readable, ref readerTable, memoryPool);
                        Assert.Equal(
                            @":method: GET
:scheme: http
:path: /
:authority: www.example.com
", httpHeader.ToString());
                        Assert.Equal(
                            @"[1] (s = 57) :authority: www.example.com
Table size: 57
", readerTable.ToString());

                        var wb = channel.Alloc();
                        Hpack.WriteHttpHeader(wb, httpHeader, ref writerTable, memoryPool);
                        Assert.Equal(hex, ToHex(wb));
                        await wb.FlushAsync();

                        Assert.Equal(
                            @"[1] (s = 57) :authority: www.example.com
Table size: 57
", writerTable.ToString());

                        hex        = "8286 84be 5808 6e6f 2d63 6163 6865";
                        readable   = HexToBuffer(ref hex);
                        httpHeader = Hpack.ParseHttpHeader(ref readable, ref readerTable, memoryPool);
                        Assert.Equal(
                            @":method: GET
:scheme: http
:path: /
:authority: www.example.com
cache-control: no-cache
", httpHeader.ToString());
                        Assert.Equal(
                            @"[1] (s = 53) cache-control: no-cache
[2] (s = 57) :authority: www.example.com
Table size: 110
", readerTable.ToString());

                        wb = channel.Alloc();
                        Hpack.WriteHttpHeader(wb, httpHeader, ref writerTable, memoryPool);
                        Assert.Equal(hex, ToHex(wb));
                        await wb.FlushAsync();

                        Assert.Equal(
                            @"[1] (s = 53) cache-control: no-cache
[2] (s = 57) :authority: www.example.com
Table size: 110
", writerTable.ToString());



                        hex        = "8287 85bf 400a 6375 7374 6f6d 2d6b 6579 0c63 7573 746f 6d2d 7661 6c75 65";
                        readable   = HexToBuffer(ref hex);
                        httpHeader = Hpack.ParseHttpHeader(ref readable, ref readerTable, memoryPool);
                        Assert.Equal(
                            @":method: GET
:scheme: https
:path: /index.html
:authority: www.example.com
custom-key: custom-value
", httpHeader.ToString());
                        Assert.Equal(
                            @"[1] (s = 54) custom-key: custom-value
[2] (s = 53) cache-control: no-cache
[3] (s = 57) :authority: www.example.com
Table size: 164
", readerTable.ToString());

                        wb = channel.Alloc();
                        Hpack.WriteHttpHeader(wb, httpHeader, ref writerTable, memoryPool);
                        Assert.Equal(hex, ToHex(wb));
                        await wb.FlushAsync();

                        Assert.Equal(
                            @"[1] (s = 54) custom-key: custom-value
[2] (s = 53) cache-control: no-cache
[3] (s = 57) :authority: www.example.com
Table size: 164
", writerTable.ToString());
                    }
                    finally
                    {
                        readerTable.Dispose();
                        writerTable.Dispose();
                    }
                }
        }