1
  
2
  
3
  
4
  
5
  
6
  
7
  
8
  
9
  
10
  
11
  
12
  
13
  
14
  
15
  
16
  
17
  
18
  
19
  
20
  
21
  
22
  
23
  
24
  
25
  
26
  
27
  
28
  
29
  
30
  
31
  
32
  
33
  
34
  
35
  
36
  
37
  
38
  
39
  
40
  
41
  
42
  
43
  
44
  
45
  
46
  
47
  
48
  
49
  
50
  
51
  
52
  
53
  
54
  
55
  
56
  
57
  
58
  
59
  
60
  
61
  
62
  
63
  
64
  
65
  
66
  
67
  
68
  
69
  
70
  
71
  
72
  
73
  
74
  
75
  
76
  
77
  
78
  
79
  
80
  
81
  
82
  
83
  
84
  
85
  
86
  
87
  
88
  
89
  
90
  
91
  
92
  
93
  
94
  
95
  
96
  
97
  
98
  
99
  
100
  
101
  
102
  
103
  
104
  
105
  
106
  
107
  
108
  
109
  
110
  
111
  
112
  
113
  
114
  
115
  
116
  
117
  
118
  
119
  
120
  
121
  
122
  
123
  
124
  
125
  
126
  
127
  
128
  
129
  
130
  
131
  
132
  
133
  
134
  
135
  
136
  
137
  
138
  
139
  
140
  
141
  
142
  
143
  
144
  
145
  
146
  
147
  
148
  
149
  
150
  
151
  
152
  
153
  
154
  
155
  
156
  
157
  
158
  
159
  
160
  
161
  
162
  
163
  
164
  
165
  
166
  
167
  
168
  
169
  
170
  
171
  
172
  
173
  
174
  
175
  
176
  
177
  
178
  
179
  
180
  
181
  
182
  
183
  
184
  
185
  
186
  
187
  
188
  
189
  
190
  
191
  
192
  
193
  
194
  
195
  
196
  
197
  
198
  
199
  
200
  
201
  
202
  
203
  
204
  
205
  
206
  
207
  
208
  
209
  
210
  
211
  
212
  
213
  
214
  
215
  
216
  
217
  
218
  
219
  
220
  
221
  
222
  
dnl -*- coding: utf-8; -*- 
START_MARKER 
 
test_compile_error( H ) 
test_compile_error( S ) 
test_do( add_constant( "H", String.hex2string ) ) 
test_do( add_constant( "S", String.string2hex ) ) 
 
dnl First some tests that the huffman codec works. 
 
dnl string 
define(test_huffman_simple, [[ 
  test_eq(Standards.HPack.huffman_decode(Standards.HPack.huffman_encode([[$1]])),[[$1]]) 
]]) 
 
dnl string, huffman_hex 
define(test_huffman_low, [[ 
  test_eq(S(Standards.HPack.huffman_encode([[$1]])), [[$2 - " " - "\n" - "\t"]]) 
  test_eq(Standards.HPack.huffman_decode(H([[$2]])), [[$1]]) 
  test_huffman_simple([[$1]]) 
]]) 
 
dnl text, huffman_hex 
define(test_huffman, [[ 
  test_huffman_low([["$1"]], [[#"$2"]]) 
]]) 
 
dnl The test vectors from RFC 7541 appendix C: 
 
dnl RFC 7541 C.4.1 
test_huffman([[www.example.com]], [[f1e3 c2e5 f23a 6ba0 ab90 f4ff]]) 
 
dnl RFC 7541 C.4.2 
test_huffman([[no-cache]], [[a8eb 1064 9cbf]]) 
 
dnl RFC 7541 C.4.3 
test_huffman([[custom-key]], [[25a8 49e9 5ba9 7d7f]]) 
test_huffman([[custom-value]], [[25a8 49e9 5bb8 e8b4 bf]]) 
 
dnl RFC 7541 C.6.1 
test_huffman([[302]], [[6402]]) 
test_huffman([[private]], [[aec3 771a 4b]]) 
test_huffman([[Mon, 21 Oct 2013 20:13:21 GMT]], 
             [[d07a be94 1054 d444 a820 0595 040b 8166 e082 a62d 1bff]]) 
test_huffman([[https://www.example.com]], 
             [[9d29 ad17 1863 c78f 0b97 c8e9 ae82 ae43 d3]]) 
 
dnl RFC 7541 C.6.2 
test_huffman([[307]], [[640e ff]]) 
 
dnl RFC 7541 C.6.3 
test_huffman([[Mon, 21 Oct 2013 20:13:22 GMT]], 
             [[d07a be94 1054 d444 a820 0595 040b 8166 e084 a62d 1bff]]) 
test_huffman([[gzip]], [[9bd9 ab]]) 
test_huffman([[foo=ASDJKHQKBZXOQWEOPIUAXQWEOIU; max-age=3600; version=1]], 
             [[94e7 821d d7f2 e6c7 b335 dfdf cd5b 3960 
               d5af 2708 7f36 72c1 ab27 0fb5 291f 9587 
               3160 65c0 03ed 4ee5 b106 3d50 07]]) 
 
dnl RFC 7541 doesn't contain any vectors that contain characters that 
dnl encode to more than one byte, so add one of our own. 
dnl This string used to trigger a buffering bug in the encoder. 
test_huffman_low(H("c5206920e56120e4206520f62e"), 
                 "ffffe4a194ffff38d4ffffa542a9fffffa57") 
 
dnl Test that all characters are both encodable and decodeable. 
test_huffman_simple([[(string)enumerate(256)]]) 
 
dnl Test that we don't have any strange special cases. 
test_do(add_constant("test_data", random_string(8192))) 
test_huffman_simple([[test_data]]) 
 
test_do(add_constant("test_data")); 
 
dnl Then some tests of encoding and decoding full HPack. 
 
test_do([[add_constant("D", Standards.HPack.Context(256));]]) 
test_do([[add_constant("E", Standards.HPack.Context(256));]]) 
test_do([[add_constant("F", Standards.HPack.Context(256));]]) 
 
dnl ref-encoding, header-array 
define(test_hpack, [[ 
  test_equal(D->decode(H([[$1]])), [[$2]]) 
  test_equal(F->decode(E->encode([[$2]])), [[$2]]) 
]]) 
 
dnl RFC 7541 C.2.1 
test_hpack("400a 6375 7374 6f6d 2d6b 6579 0d63 7573 746f 6d2d 6865 6164 6572", 
           [[({ ({ "custom-key", "custom-header" }) })]]) 
 
dnl RFC 7541 C.2.2 
test_hpack("040c 2f73 616d 706c 652f 7061 7468", 
           [[({ ({ ":path", "/sample/path" }) })]]) 
 
dnl RFC 7541 C.2.3 
test_hpack("1008 7061 7373 776f 7264 0673 6563 7265 74", 
           [[({ ({ "password", "secret", Standards.HPack.HEADER_NEVER_INDEXED }) })]]) 
 
dnl RFC 7541 C.2.4 
test_hpack("82", 
           [[({ ({ ":method", "GET" }) })]]) 
 
dnl RFC 7541 C.3.1 
test_hpack("8286 8441 0f77 7777 2e65 7861 6d70 6c65 2e63 6f6d", 
           [[({ ({ ":method", "GET" }), 
                ({ ":scheme", "http" }), 
                ({ ":path", "/" }), 
                ({ ":authority", "www.example.com" }) })]]) 
 
dnl RFC 7541 C.3.2 
test_hpack("8286 84be 5808 6e6f 2d63 6163 6865", 
           [[({ ({ ":method", "GET" }), 
                ({ ":scheme", "http" }), 
                ({ ":path", "/" }), 
                ({ ":authority", "www.example.com" }), 
                ({ "cache-control", "no-cache" }) })]]) 
 
dnl RFC 7541 C.3.3 
test_hpack("8287 85bf 400a 6375 7374 6f6d 2d6b 6579 0c63 7573 746f 6d2d 7661 6c75 65", 
           [[({ ({ ":method", "GET" }), 
                ({ ":scheme", "https" }), 
                ({ ":path", "/index.html" }), 
                ({ ":authority", "www.example.com" }), 
                ({ "custom-key", "custom-value" }) })]]) 
 
dnl RFC 7541 C.4.1 
test_hpack("8286 8441 8cf1 e3c2 e5f2 3a6b a0ab 90f4 ff", 
           [[({ ({ ":method", "GET" }), 
                ({ ":scheme", "http" }), 
                ({ ":path", "/" }), 
                ({ ":authority", "www.example.com" }) })]]) 
 
dnl RFC 7541 C.4.2 
test_hpack("8286 84be 5886 a8eb 1064 9cbf", 
           [[({ ({ ":method", "GET" }), 
                ({ ":scheme", "http" }), 
                ({ ":path", "/" }), 
                ({ ":authority", "www.example.com" }), 
                ({ "cache-control", "no-cache" }) })]]) 
 
dnl RFC 7541 C.4.3 
test_hpack("8287 85bf 4088 25a8 49e9 5ba9 7d7f 8925 a849 e95b b8e8 b4bf", 
           [[({ ({ ":method", "GET" }), 
                ({ ":scheme", "https" }), 
                ({ ":path", "/index.html" }), 
                ({ ":authority", "www.example.com" }), 
                ({ "custom-key", "custom-value" }) })]]) 
 
dnl RFC 7541 C.5.1 
test_hpack("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", 
           [[({ ({ ":status", "302" }), 
                ({ "cache-control", "private" }), 
                ({ "date", "Mon, 21 Oct 2013 20:13:21 GMT" }), 
                ({ "location", "https://www.example.com" }) })]]) 
 
dnl RFC 7541 C.5.2 
test_hpack("4803 3330 37c1 c0bf", 
           [[({ ({ ":status", "307" }), 
                ({ "cache-control", "private" }), 
                ({ "date", "Mon, 21 Oct 2013 20:13:21 GMT" }), 
                ({ "location", "https://www.example.com" }) })]]) 
 
dnl RFC 7541 C.5.3 
test_hpack("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", 
           [[({ ({ ":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" }) })]]) 
 
dnl RFC 7541 C.6.1 
test_hpack("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", 
           [[({ ({ ":status", "302" }), 
                ({ "cache-control", "private" }), 
                ({ "date", "Mon, 21 Oct 2013 20:13:21 GMT" }), 
                ({ "location", "https://www.example.com" }) })]]) 
 
dnl RFC 7541 C.6.2 
test_hpack("4883 640e ffc1 c0bf", 
           [[({ ({ ":status", "307" }), 
                ({ "cache-control", "private" }), 
                ({ "date", "Mon, 21 Oct 2013 20:13:21 GMT" }), 
                ({ "location", "https://www.example.com" }) })]]) 
 
dnl RFC 7541 C.6.3 
test_hpack("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", 
           [[({ ({ ":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" }) })]]) 
 
 
test_do(add_constant("F")) 
test_do(add_constant("E")) 
test_do(add_constant("D")) 
test_do(add_constant("S")) 
test_do(add_constant("H")) 
 
END_MARKER