Пример #1
0
        static void GenerateSeed(EncodeSeedDelegate encodeFunc)
        {
            byte[] buffer  = new byte[1024 * 1024];
            var    encoder = new HPackEncoder(buffer);

            encodeFunc(encoder);
            encoder.VerifyComplete();

            File.WriteAllBytes($"seed_{++seedNo}.bin", buffer.AsSpan(0, encoder.BytesWritten).ToArray());
        }
Пример #2
0
        static void RunTests()
        {
            Test("literal header field with indexing",
                 new byte[] { 0x40, 0x0a, 0x63, 0x75, 0x73, 0x74, 0x6f, 0x6d, 0x2d, 0x6b, 0x65, 0x79, 0x0d, 0x63, 0x75, 0x73, 0x74, 0x6f, 0x6d, 0x2d, 0x68, 0x65, 0x61, 0x64, 0x65, 0x72 },
                 buffer =>
            {
                int bytes = HPackEncoder.EncodeHeader("custom-key", "custom-header", HPackFlags.NewIndexed, buffer.Span);
                return(bytes);
            });

            Test("literal header field without indexing",
                 new byte[] { 0x04, 0x0c, 0x2f, 0x73, 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x2f, 0x70, 0x61, 0x74, 0x68 },
                 buffer =>
            {
                int bytes = HPackEncoder.EncodeHeader(HPackEncoder.GetStaticIndex(":path"), "/sample/path", HPackFlags.WithoutIndexing, buffer.Span);
                return(bytes);
            });

            Test("literal header never indexed",
                 new byte[] { 0x10, 0x08, 0x70, 0x61, 0x73, 0x73, 0x77, 0x6f, 0x72, 0x64, 0x06, 0x73, 0x65, 0x63, 0x72, 0x65, 0x74 },
                 buffer =>
            {
                int bytes = HPackEncoder.EncodeHeader("password", "secret", HPackFlags.NeverIndexed, buffer.Span);
                return(bytes);
            });

            Test("indexed header field using dynamic table",
                 new byte[]
            {
                // Newly indexed literal header.
                0x40, 0x0a, 0x63, 0x75, 0x73, 0x74, 0x6f, 0x6d, 0x2d, 0x6b, 0x65, 0x79, 0x0d, 0x63, 0x75, 0x73, 0x74, 0x6f, 0x6d, 0x2d, 0x68, 0x65, 0x61, 0x64, 0x65, 0x72,
                // Indexed header using dynamic table for full name/value.
                0xBE,
                // Header using dynamic table for just name, with a literal value.
                0x0F, 0x2F, 0x0A, 0x6E, 0x65, 0x77, 0x2D, 0x68, 0x65, 0x61, 0x64, 0x65, 0x72
            },
                 buffer =>
            {
                return(new HPackEncoder(buffer)
                       .Encode("custom-key", "custom-header", HPackFlags.NewIndexed)
                       .Encode("custom-key", "custom-header", HPackFlags.WithoutIndexing)
                       .Encode("custom-key", "new-header", HPackFlags.None)
                       .VerifyComplete()
                       .BytesWritten);
            });
        }