public void CompressAndDecompressSimpleDataX2()
        {
            CompressionProcessor compressor = new CompressionProcessor();

            byte[] data = new byte[] { 0x65, 0x66, 0x67, 0x68 };

            byte[] compressedData = compressor.Compress(data);
            byte[] decompressedData = compressor.Decompress(compressedData);
            Assert.Equal(data, decompressedData);

            compressedData = compressor.Compress(data);
            decompressedData = compressor.Decompress(compressedData);
            Assert.Equal(data, decompressedData);
        }
Пример #2
0
        public void ClearReferenceSet()
        {
            var bytes = new byte[] { 0x30 }; // this value depends on pattern

            var clientHeaders = new HeadersList
            {
                new KeyValuePair <string, string>(":method", "get")
            };

            var clientCompressionProc = new CompressionProcessor();
            var serverCompressionProc = new CompressionProcessor();

            serverCompressionProc.Decompress(clientCompressionProc.Compress(clientHeaders));

            stateBefore = new CompProcState(serverCompressionProc);

            Assert.True(stateBefore.LocalRefSet.Count > 0);

            serverCompressionProc.Decompress(bytes);

            stateAfter = new CompProcState(serverCompressionProc);

            serverCompressionProc.Dispose();
            clientCompressionProc.Dispose();

            Assert.True(stateAfter.LocalRefSet == null ||
                        stateAfter.LocalRefSet.Count == 0);
        }
        public void CompressAndDecompressEmptyData()
        {
            CompressionProcessor compressor = new CompressionProcessor();

            byte[] data = new byte[10];

            byte[] compressedData = compressor.Compress(data);
            byte[] decompressedData = compressor.Decompress(compressedData);

            Assert.Equal(data, decompressedData);
        }
Пример #4
0
        public void CompressionSuccessful()
        {
            var clientHeaders = new HeadersList
            {
                new KeyValuePair <string, string>(":method", "get"),
                new KeyValuePair <string, string>(":path", "/test.txt"),
                new KeyValuePair <string, string>(":version", Protocols.Http2),
                new KeyValuePair <string, string>(":host", "localhost"),
                new KeyValuePair <string, string>(":scheme", "http"),
            };
            var clientCompressor   = new CompressionProcessor(ConnectionEnd.Client);
            var serverDecompressor = new CompressionProcessor(ConnectionEnd.Server);

            var serializedHeaders   = clientCompressor.Compress(clientHeaders);
            var decompressedHeaders = new HeadersList(serverDecompressor.Decompress(serializedHeaders));

            foreach (var t in clientHeaders)
            {
                Assert.Equal(decompressedHeaders.GetValue(t.Key), t.Value);
            }

            var serverHeaders = new HeadersList
            {
                new KeyValuePair <string, string>(":status", StatusCode.Code200Ok.ToString()),
            };
            var serverCompressor   = new CompressionProcessor(ConnectionEnd.Server);
            var clientDecompressor = new CompressionProcessor(ConnectionEnd.Client);

            serializedHeaders   = serverCompressor.Compress(serverHeaders);
            decompressedHeaders = new HeadersList(clientCompressor.Decompress(serializedHeaders));

            foreach (var t in serverHeaders)
            {
                Assert.Equal(decompressedHeaders.GetValue(t.Key), t.Value);
            }
        }
Пример #5
0
        public void HeadersCompression()
        {
            var clientHeaders = new HeadersList
            {
                new KeyValuePair <string, string>(":method", "get"),
                new KeyValuePair <string, string>(":path", "/Y3A9NTcuNjE2NjY1fjM5Ljg2NjY2NSZsdmw9NyZzdHk9ciZxPVlhcm9zbGF2bA=="),
                new KeyValuePair <string, string>(":version", Protocols.Http2),
                new KeyValuePair <string, string>(":host", "localhost"),
                new KeyValuePair <string, string>(":scheme", "https"),
            };
            var clientCompressionProc = new CompressionProcessor();
            var serverCompressionProc = new CompressionProcessor();

            var serializedHeaders   = clientCompressionProc.Compress(clientHeaders);
            var decompressedHeaders = new HeadersList(serverCompressionProc.Decompress(serializedHeaders));

            foreach (var t in clientHeaders)
            {
                Assert.Equal(decompressedHeaders.GetValue(t.Key), t.Value);
            }

            var serverHeaders = new HeadersList
            {
                new KeyValuePair <string, string>(":method", "get"),
                new KeyValuePair <string, string>(":path", "/simpleTest.txt"),
                new KeyValuePair <string, string>(":version", Protocols.Http2),
                new KeyValuePair <string, string>(":host", "localhost"),
                new KeyValuePair <string, string>(":scheme", "https"),
            };

            serializedHeaders   = serverCompressionProc.Compress(serverHeaders);
            decompressedHeaders = new HeadersList(clientCompressionProc.Decompress(serializedHeaders));

            foreach (var t in serverHeaders)
            {
                Assert.Equal(decompressedHeaders.GetValue(t.Key), t.Value);
            }

            serverHeaders = new HeadersList
            {
                new KeyValuePair <string, string>(":status", StatusCode.Code404NotFound.ToString(CultureInfo.InvariantCulture)),
            };

            serializedHeaders   = serverCompressionProc.Compress(serverHeaders);
            decompressedHeaders = new HeadersList(clientCompressionProc.Decompress(serializedHeaders));

            foreach (var t in serverHeaders)
            {
                Assert.Equal(decompressedHeaders.GetValue(t.Key), t.Value);
            }

            serverHeaders = new HeadersList
            {
                new KeyValuePair <string, string>("content-type", "text/plain"),
                new KeyValuePair <string, string>("last-modified", "Wed, 23 Oct 2013 21:32:06 GMT"),
                new KeyValuePair <string, string>("etag", "1cedo15cb041fc1"),
                new KeyValuePair <string, string>("content-length", "749761"),
                new KeyValuePair <string, string>(":status", StatusCode.Code200Ok.ToString(CultureInfo.InvariantCulture)),
            };

            serializedHeaders   = serverCompressionProc.Compress(serverHeaders);
            decompressedHeaders = new HeadersList(clientCompressionProc.Decompress(serializedHeaders));

            foreach (var t in serverHeaders)
            {
                Assert.Equal(decompressedHeaders.GetValue(t.Key), t.Value);
            }

            clientHeaders = new HeadersList
            {
                new KeyValuePair <string, string>(":method", "get"),
                new KeyValuePair <string, string>(":path", "/index.html"),
                new KeyValuePair <string, string>(":version", Protocols.Http2),
                new KeyValuePair <string, string>(":host", "localhost"),
                new KeyValuePair <string, string>(":scheme", "https"),
            };

            serializedHeaders   = clientCompressionProc.Compress(clientHeaders);
            decompressedHeaders = new HeadersList(serverCompressionProc.Decompress(serializedHeaders));

            foreach (var t in clientHeaders)
            {
                Assert.Equal(decompressedHeaders.GetValue(t.Key), t.Value);
            }
        }