1 /*
2 * nghttp2 - HTTP/2 C Library
3 *
4 * Copyright (c) 2013 Tatsuhiro Tsujikawa
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining
7 * a copy of this software and associated documentation files (the
8 * "Software"), to deal in the Software without restriction, including
9 * without limitation the rights to use, copy, modify, merge, publish,
10 * distribute, sublicense, and/or sell copies of the Software, and to
11 * permit persons to whom the Software is furnished to do so, subject to
12 * the following conditions:
13 *
14 * The above copyright notice and this permission notice shall be
15 * included in all copies or substantial portions of the Software.
16 *
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
21 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
22 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
23 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 */
25 #include "http2_test.h"
26
27 #include <cassert>
28 #include <cstring>
29 #include <iostream>
30
31 #include "munitxx.h"
32
33 #include "url-parser/url_parser.h"
34
35 #include "http2.h"
36 #include "util.h"
37
38 using namespace nghttp2;
39 using namespace std::literals;
40
41 #define MAKE_NV(K, V) \
42 { \
43 (uint8_t *)K, (uint8_t *)V, sizeof(K) - 1, sizeof(V) - 1, \
44 NGHTTP2_NV_FLAG_NONE \
45 }
46
47 namespace shrpx {
48
49 namespace {
50 const MunitTest tests[]{
51 munit_void_test(test_http2_add_header),
52 munit_void_test(test_http2_get_header),
53 munit_void_test(test_http2_copy_headers_to_nva),
54 munit_void_test(test_http2_build_http1_headers_from_headers),
55 munit_void_test(test_http2_lws),
56 munit_void_test(test_http2_rewrite_location_uri),
57 munit_void_test(test_http2_parse_http_status_code),
58 munit_void_test(test_http2_index_header),
59 munit_void_test(test_http2_lookup_token),
60 munit_void_test(test_http2_parse_link_header),
61 munit_void_test(test_http2_path_join),
62 munit_void_test(test_http2_normalize_path),
63 munit_void_test(test_http2_rewrite_clean_path),
64 munit_void_test(test_http2_get_pure_path_component),
65 munit_void_test(test_http2_construct_push_component),
66 munit_void_test(test_http2_contains_trailers),
67 munit_void_test(test_http2_check_transfer_encoding),
68 munit_test_end(),
69 };
70 } // namespace
71
72 const MunitSuite http2_suite{
73 "/http2", tests, NULL, 1, MUNIT_SUITE_OPTION_NONE,
74 };
75
76 namespace {
check_nv(const HeaderRef & a,const nghttp2_nv * b)77 void check_nv(const HeaderRef &a, const nghttp2_nv *b) {
78 assert_size(a.name.size(), ==, b->namelen);
79 assert_size(a.value.size(), ==, b->valuelen);
80 assert_memory_equal(b->namelen, a.name.data(), b->name);
81 assert_memory_equal(b->valuelen, a.value.data(), b->value);
82 }
83 } // namespace
84
test_http2_add_header(void)85 void test_http2_add_header(void) {
86 auto nva = Headers();
87
88 http2::add_header(nva, "alpha"_sr, "123"_sr, false, -1);
89 assert_true(Headers::value_type("alpha", "123") == nva[0]);
90 assert_false(nva[0].no_index);
91
92 nva.clear();
93
94 http2::add_header(nva, "alpha"_sr, ""_sr, true, -1);
95 assert_true(Headers::value_type("alpha", "") == nva[0]);
96 assert_true(nva[0].no_index);
97
98 nva.clear();
99
100 http2::add_header(nva, "a"_sr, "b"_sr, false, -1);
101 assert_true(Headers::value_type("a", "b") == nva[0]);
102
103 nva.clear();
104
105 http2::add_header(nva, "te"_sr, "trailers"_sr, false, http2::HD_TE);
106 assert_int32(http2::HD_TE, ==, nva[0].token);
107 }
108
test_http2_get_header(void)109 void test_http2_get_header(void) {
110 auto nva = Headers{{"alpha", "1"}, {"bravo", "2"}, {"bravo", "3"},
111 {"charlie", "4"}, {"delta", "5"}, {"echo", "6"},
112 {"content-length", "7"}};
113 const Headers::value_type *rv;
114 rv = http2::get_header(nva, "delta");
115 assert_not_null(rv);
116 assert_stdstring_equal("delta", rv->name);
117
118 rv = http2::get_header(nva, "bravo");
119 assert_not_null(rv);
120 assert_stdstring_equal("bravo", rv->name);
121
122 rv = http2::get_header(nva, "foxtrot");
123 assert_null(rv);
124
125 http2::HeaderIndex hdidx;
126 http2::init_hdidx(hdidx);
127 hdidx[http2::HD_CONTENT_LENGTH] = 6;
128 rv = http2::get_header(hdidx, http2::HD_CONTENT_LENGTH, nva);
129 assert_stdstring_equal("content-length", rv->name);
130 }
131
132 namespace {
133 auto headers = HeaderRefs{
134 {"alpha"_sr, "0"_sr, true},
135 {"bravo"_sr, "1"_sr},
136 {"connection"_sr, "2"_sr, false, http2::HD_CONNECTION},
137 {"connection"_sr, "3"_sr, false, http2::HD_CONNECTION},
138 {"delta"_sr, "4"_sr},
139 {"expect"_sr, "5"_sr},
140 {"foxtrot"_sr, "6"_sr},
141 {"tango"_sr, "7"_sr},
142 {"te"_sr, "8"_sr, false, http2::HD_TE},
143 {"te"_sr, "9"_sr, false, http2::HD_TE},
144 {"x-forwarded-proto"_sr, "10"_sr, false, http2::HD_X_FORWARDED_FOR},
145 {"x-forwarded-proto"_sr, "11"_sr, false, http2::HD_X_FORWARDED_FOR},
146 {"zulu"_sr, "12"_sr}};
147 } // namespace
148
149 namespace {
150 auto headers2 = HeaderRefs{
151 {"x-forwarded-for"_sr, "xff1"_sr, false, http2::HD_X_FORWARDED_FOR},
152 {"x-forwarded-for"_sr, "xff2"_sr, false, http2::HD_X_FORWARDED_FOR},
153 {"x-forwarded-proto"_sr, "xfp1"_sr, false, http2::HD_X_FORWARDED_PROTO},
154 {"x-forwarded-proto"_sr, "xfp2"_sr, false, http2::HD_X_FORWARDED_PROTO},
155 {"forwarded"_sr, "fwd1"_sr, false, http2::HD_FORWARDED},
156 {"forwarded"_sr, "fwd2"_sr, false, http2::HD_FORWARDED},
157 {"via"_sr, "via1"_sr, false, http2::HD_VIA},
158 {"via"_sr, "via2"_sr, false, http2::HD_VIA},
159 };
160 } // namespace
161
test_http2_copy_headers_to_nva(void)162 void test_http2_copy_headers_to_nva(void) {
163 auto ans = std::vector<int>{0, 1, 4, 5, 6, 7, 12};
164 std::vector<nghttp2_nv> nva;
165
166 http2::copy_headers_to_nva_nocopy(nva, headers,
167 http2::HDOP_STRIP_X_FORWARDED_FOR);
168 assert_size(7, ==, nva.size());
169 for (size_t i = 0; i < ans.size(); ++i) {
170 check_nv(headers[ans[i]], &nva[i]);
171
172 if (ans[i] == 0) {
173 assert_uint8((NGHTTP2_NV_FLAG_NO_COPY_NAME |
174 NGHTTP2_NV_FLAG_NO_COPY_VALUE | NGHTTP2_NV_FLAG_NO_INDEX),
175 ==, nva[i].flags);
176 } else {
177 assert_uint8(
178 (NGHTTP2_NV_FLAG_NO_COPY_NAME | NGHTTP2_NV_FLAG_NO_COPY_VALUE), ==,
179 nva[i].flags);
180 }
181 }
182
183 nva.clear();
184 http2::copy_headers_to_nva(nva, headers, http2::HDOP_STRIP_X_FORWARDED_FOR);
185 assert_size(7, ==, nva.size());
186 for (size_t i = 0; i < ans.size(); ++i) {
187 check_nv(headers[ans[i]], &nva[i]);
188
189 if (ans[i] == 0) {
190 assert_true(nva[i].flags & NGHTTP2_NV_FLAG_NO_INDEX);
191 } else {
192 assert_false(nva[i].flags);
193 }
194 }
195
196 nva.clear();
197
198 auto ans2 = std::vector<int>{0, 2, 4, 6};
199 http2::copy_headers_to_nva(nva, headers2, http2::HDOP_NONE);
200 assert_size(ans2.size(), ==, nva.size());
201 for (size_t i = 0; i < ans2.size(); ++i) {
202 check_nv(headers2[ans2[i]], &nva[i]);
203 }
204
205 nva.clear();
206
207 http2::copy_headers_to_nva(nva, headers2, http2::HDOP_STRIP_ALL);
208 assert_true(nva.empty());
209 }
210
test_http2_build_http1_headers_from_headers(void)211 void test_http2_build_http1_headers_from_headers(void) {
212 MemchunkPool pool;
213 DefaultMemchunks buf(&pool);
214 http2::build_http1_headers_from_headers(&buf, headers,
215 http2::HDOP_STRIP_X_FORWARDED_FOR);
216 auto hdrs = std::string(buf.head->pos, buf.head->last);
217 assert_stdstring_equal("Alpha: 0\r\n"
218 "Bravo: 1\r\n"
219 "Delta: 4\r\n"
220 "Expect: 5\r\n"
221 "Foxtrot: 6\r\n"
222 "Tango: 7\r\n"
223 "Te: 8\r\n"
224 "Te: 9\r\n"
225 "Zulu: 12\r\n",
226 hdrs);
227
228 buf.reset();
229
230 http2::build_http1_headers_from_headers(&buf, headers2, http2::HDOP_NONE);
231 hdrs = std::string(buf.head->pos, buf.head->last);
232 assert_stdstring_equal("X-Forwarded-For: xff1\r\n"
233 "X-Forwarded-Proto: xfp1\r\n"
234 "Forwarded: fwd1\r\n"
235 "Via: via1\r\n",
236 hdrs);
237
238 buf.reset();
239
240 http2::build_http1_headers_from_headers(&buf, headers2,
241 http2::HDOP_STRIP_ALL);
242 assert_size(0, ==, buf.rleft());
243 }
244
test_http2_lws(void)245 void test_http2_lws(void) {
246 assert_false(http2::lws("alpha"));
247 assert_true(http2::lws(" "));
248 assert_true(http2::lws(""));
249 }
250
251 namespace {
check_rewrite_location_uri(const std::string & want,const std::string & uri,const std::string & match_host,const std::string & req_authority,const std::string & upstream_scheme)252 void check_rewrite_location_uri(const std::string &want, const std::string &uri,
253 const std::string &match_host,
254 const std::string &req_authority,
255 const std::string &upstream_scheme) {
256 BlockAllocator balloc(4096, 4096);
257 http_parser_url u{};
258 assert_int(0, ==, http_parser_parse_url(uri.c_str(), uri.size(), 0, &u));
259 auto got = http2::rewrite_location_uri(
260 balloc, StringRef{uri}, u, StringRef{match_host},
261 StringRef{req_authority}, StringRef{upstream_scheme});
262 assert_stdsv_equal(want, got);
263 }
264 } // namespace
265
test_http2_rewrite_location_uri(void)266 void test_http2_rewrite_location_uri(void) {
267 check_rewrite_location_uri("https://localhost:3000/alpha?bravo#charlie",
268 "http://localhost:3001/alpha?bravo#charlie",
269 "localhost:3001", "localhost:3000", "https");
270 check_rewrite_location_uri("https://localhost/", "http://localhost:3001/",
271 "localhost", "localhost", "https");
272 check_rewrite_location_uri("http://localhost/", "http://localhost:3001/",
273 "localhost", "localhost", "http");
274 check_rewrite_location_uri("http://localhost:443/", "http://localhost:3001/",
275 "localhost", "localhost:443", "http");
276 check_rewrite_location_uri("https://localhost:80/", "http://localhost:3001/",
277 "localhost", "localhost:80", "https");
278 check_rewrite_location_uri("", "http://localhost:3001/", "127.0.0.1",
279 "127.0.0.1", "https");
280 check_rewrite_location_uri("https://localhost:3000/",
281 "http://localhost:3001/", "localhost",
282 "localhost:3000", "https");
283 check_rewrite_location_uri("https://localhost:3000/", "http://localhost/",
284 "localhost", "localhost:3000", "https");
285
286 // match_host != req_authority
287 check_rewrite_location_uri("https://example.org", "http://127.0.0.1:8080",
288 "127.0.0.1", "example.org", "https");
289 check_rewrite_location_uri("", "http://example.org", "127.0.0.1",
290 "example.org", "https");
291 }
292
test_http2_parse_http_status_code(void)293 void test_http2_parse_http_status_code(void) {
294 assert_int(200, ==, http2::parse_http_status_code("200"_sr));
295 assert_int(102, ==, http2::parse_http_status_code("102"_sr));
296 assert_int(-1, ==, http2::parse_http_status_code("099"_sr));
297 assert_int(-1, ==, http2::parse_http_status_code("99"_sr));
298 assert_int(-1, ==, http2::parse_http_status_code("-1"_sr));
299 assert_int(-1, ==, http2::parse_http_status_code("20a"_sr));
300 assert_int(-1, ==, http2::parse_http_status_code(StringRef{}));
301 }
302
test_http2_index_header(void)303 void test_http2_index_header(void) {
304 http2::HeaderIndex hdidx;
305 http2::init_hdidx(hdidx);
306
307 http2::index_header(hdidx, http2::HD__AUTHORITY, 0);
308 http2::index_header(hdidx, -1, 1);
309
310 assert_uint16(0, ==, hdidx[http2::HD__AUTHORITY]);
311 }
312
test_http2_lookup_token(void)313 void test_http2_lookup_token(void) {
314 assert_int(http2::HD__AUTHORITY, ==, http2::lookup_token(":authority"_sr));
315 assert_int(-1, ==, http2::lookup_token(":authorit"_sr));
316 assert_int(-1, ==, http2::lookup_token(":Authority"_sr));
317 assert_int(http2::HD_EXPECT, ==, http2::lookup_token("expect"_sr));
318 }
319
test_http2_parse_link_header(void)320 void test_http2_parse_link_header(void) {
321 {
322 // only URI appears; we don't extract URI unless it bears rel=preload
323 auto res = http2::parse_link_header("<url>"_sr);
324 assert_size(0, ==, res.size());
325 }
326 {
327 // URI url should be extracted
328 auto res = http2::parse_link_header("<url>; rel=preload"_sr);
329 assert_size(1, ==, res.size());
330 assert_stdsv_equal("url"sv, res[0].uri);
331 }
332 {
333 // With extra link-param. URI url should be extracted
334 auto res = http2::parse_link_header("<url>; rel=preload; as=file"_sr);
335 assert_size(1, ==, res.size());
336 assert_stdsv_equal("url"sv, res[0].uri);
337 }
338 {
339 // With extra link-param. URI url should be extracted
340 auto res = http2::parse_link_header("<url>; as=file; rel=preload"_sr);
341 assert_size(1, ==, res.size());
342 assert_stdsv_equal("url"sv, res[0].uri);
343 }
344 {
345 // With extra link-param and quote-string. URI url should be
346 // extracted
347 auto res =
348 http2::parse_link_header(R"(<url>; rel=preload; title="foo,bar")"_sr);
349 assert_size(1, ==, res.size());
350 assert_stdsv_equal("url"sv, res[0].uri);
351 }
352 {
353 // With extra link-param and quote-string. URI url should be
354 // extracted
355 auto res =
356 http2::parse_link_header(R"(<url>; title="foo,bar"; rel=preload)"_sr);
357 assert_size(1, ==, res.size());
358 assert_stdsv_equal("url"sv, res[0].uri);
359 }
360 {
361 // ',' after quote-string
362 auto res = http2::parse_link_header(
363 R"(<url>; title="foo,bar", <url2>; rel=preload)"_sr);
364 assert_size(1, ==, res.size());
365 assert_stdsv_equal("url2"sv, res[0].uri);
366 }
367 {
368 // Only first URI should be extracted.
369 auto res = http2::parse_link_header("<url>; rel=preload, <url2>"_sr);
370 assert_size(1, ==, res.size());
371 assert_stdsv_equal("url"sv, res[0].uri);
372 }
373 {
374 // Both have rel=preload, so both urls should be extracted
375 auto res =
376 http2::parse_link_header("<url>; rel=preload, <url2>; rel=preload"_sr);
377 assert_size(2, ==, res.size());
378 assert_stdsv_equal("url"sv, res[0].uri);
379 assert_stdsv_equal("url2"sv, res[1].uri);
380 }
381 {
382 // Second URI uri should be extracted.
383 auto res = http2::parse_link_header("<url>, <url2>;rel=preload"_sr);
384 assert_size(1, ==, res.size());
385 assert_stdsv_equal("url2"sv, res[0].uri);
386 }
387 {
388 // Error if input ends with ';'
389 auto res = http2::parse_link_header("<url>;rel=preload;"_sr);
390 assert_size(0, ==, res.size());
391 }
392 {
393 // Error if link header ends with ';'
394 auto res = http2::parse_link_header("<url>;rel=preload;, <url>"_sr);
395 assert_size(0, ==, res.size());
396 }
397 {
398 // OK if input ends with ','
399 auto res = http2::parse_link_header("<url>;rel=preload,"_sr);
400 assert_size(1, ==, res.size());
401 assert_stdsv_equal("url"sv, res[0].uri);
402 }
403 {
404 // Multiple repeated ','s between fields is OK
405 auto res = http2::parse_link_header("<url>,,,<url2>;rel=preload"_sr);
406 assert_size(1, ==, res.size());
407 assert_stdsv_equal("url2"sv, res[0].uri);
408 }
409 {
410 // Error if url is not enclosed by <>
411 auto res = http2::parse_link_header("url>;rel=preload"_sr);
412 assert_size(0, ==, res.size());
413 }
414 {
415 // Error if url is not enclosed by <>
416 auto res = http2::parse_link_header("<url;rel=preload"_sr);
417 assert_size(0, ==, res.size());
418 }
419 {
420 // Empty parameter value is not allowed
421 auto res = http2::parse_link_header("<url>;rel=preload; as="_sr);
422 assert_size(0, ==, res.size());
423 }
424 {
425 // Empty parameter value is not allowed
426 auto res = http2::parse_link_header("<url>;as=;rel=preload"_sr);
427 assert_size(0, ==, res.size());
428 }
429 {
430 // Empty parameter value is not allowed
431 auto res = http2::parse_link_header("<url>;as=, <url>;rel=preload"_sr);
432 assert_size(0, ==, res.size());
433 }
434 {
435 // Empty parameter name is not allowed
436 auto res = http2::parse_link_header("<url>; =file; rel=preload"_sr);
437 assert_size(0, ==, res.size());
438 }
439 {
440 // Without whitespaces
441 auto res = http2::parse_link_header(
442 "<url>;as=file;rel=preload,<url2>;rel=preload"_sr);
443 assert_size(2, ==, res.size());
444 assert_stdsv_equal("url"sv, res[0].uri);
445 assert_stdsv_equal("url2"sv, res[1].uri);
446 }
447 {
448 // link-extension may have no value
449 auto res = http2::parse_link_header("<url>; as; rel=preload"_sr);
450 assert_size(1, ==, res.size());
451 assert_stdsv_equal("url"sv, res[0].uri);
452 }
453 {
454 // ext-name-star
455 auto res = http2::parse_link_header("<url>; foo*=bar; rel=preload"_sr);
456 assert_size(1, ==, res.size());
457 assert_stdsv_equal("url"sv, res[0].uri);
458 }
459 {
460 // '*' is not allowed expect for trailing one
461 auto res = http2::parse_link_header("<url>; *=bar; rel=preload"_sr);
462 assert_size(0, ==, res.size());
463 }
464 {
465 // '*' is not allowed expect for trailing one
466 auto res = http2::parse_link_header("<url>; foo*bar=buzz; rel=preload"_sr);
467 assert_size(0, ==, res.size());
468 }
469 {
470 // ext-name-star must be followed by '='
471 auto res = http2::parse_link_header("<url>; foo*; rel=preload"_sr);
472 assert_size(0, ==, res.size());
473 }
474 {
475 // '>' is not followed by ';'
476 auto res = http2::parse_link_header("<url> rel=preload"_sr);
477 assert_size(0, ==, res.size());
478 }
479 {
480 // Starting with whitespace is no problem.
481 auto res = http2::parse_link_header(" <url>; rel=preload"_sr);
482 assert_size(1, ==, res.size());
483 assert_stdsv_equal("url"sv, res[0].uri);
484 }
485 {
486 // preload is a prefix of bogus rel parameter value
487 auto res = http2::parse_link_header("<url>; rel=preloadx"_sr);
488 assert_size(0, ==, res.size());
489 }
490 {
491 // preload in relation-types list
492 auto res = http2::parse_link_header(R"(<url>; rel="preload")"_sr);
493 assert_size(1, ==, res.size());
494 assert_stdsv_equal("url"sv, res[0].uri);
495 }
496 {
497 // preload in relation-types list followed by another parameter
498 auto res = http2::parse_link_header(R"(<url>; rel="preload foo")"_sr);
499 assert_size(1, ==, res.size());
500 assert_stdsv_equal("url"sv, res[0].uri);
501 }
502 {
503 // preload in relation-types list following another parameter
504 auto res = http2::parse_link_header(R"(<url>; rel="foo preload")"_sr);
505 assert_size(1, ==, res.size());
506 assert_stdsv_equal("url"sv, res[0].uri);
507 }
508 {
509 // preload in relation-types list between other parameters
510 auto res = http2::parse_link_header(R"(<url>; rel="foo preload bar")"_sr);
511 assert_size(1, ==, res.size());
512 assert_stdsv_equal("url"sv, res[0].uri);
513 }
514 {
515 // preload in relation-types list between other parameters
516 auto res =
517 http2::parse_link_header(R"(<url>; rel="foo preload bar")"_sr);
518 assert_size(1, ==, res.size());
519 assert_stdsv_equal("url"sv, res[0].uri);
520 }
521 {
522 // no preload in relation-types list
523 auto res = http2::parse_link_header(R"(<url>; rel="foo")"_sr);
524 assert_size(0, ==, res.size());
525 }
526 {
527 // no preload in relation-types list, multiple unrelated elements.
528 auto res = http2::parse_link_header(R"(<url>; rel="foo bar")"_sr);
529 assert_size(0, ==, res.size());
530 }
531 {
532 // preload in relation-types list, followed by another link-value.
533 auto res = http2::parse_link_header(R"(<url>; rel="preload", <url2>)"_sr);
534 assert_size(1, ==, res.size());
535 assert_stdsv_equal("url"sv, res[0].uri);
536 }
537 {
538 // preload in relation-types list, following another link-value.
539 auto res = http2::parse_link_header(R"(<url>, <url2>; rel="preload")"_sr);
540 assert_size(1, ==, res.size());
541 assert_stdsv_equal("url2"sv, res[0].uri);
542 }
543 {
544 // preload in relation-types list, followed by another link-param.
545 auto res =
546 http2::parse_link_header(R"(<url>; rel="preload"; as="font")"_sr);
547 assert_size(1, ==, res.size());
548 assert_stdsv_equal("url"sv, res[0].uri);
549 }
550 {
551 // preload in relation-types list, followed by character other
552 // than ';' or ','
553 auto res = http2::parse_link_header(R"(<url>; rel="preload".)"_sr);
554 assert_size(0, ==, res.size());
555 }
556 {
557 // preload in relation-types list, followed by ';' but it
558 // terminates input
559 auto res = http2::parse_link_header(R"(<url>; rel="preload";)"_sr);
560 assert_size(0, ==, res.size());
561 }
562 {
563 // preload in relation-types list, followed by ',' but it
564 // terminates input
565 auto res = http2::parse_link_header(R"(<url>; rel="preload",)"_sr);
566 assert_size(1, ==, res.size());
567 assert_stdsv_equal("url"sv, res[0].uri);
568 }
569 {
570 // preload in relation-types list but there is preceding white
571 // space.
572 auto res = http2::parse_link_header(R"(<url>; rel=" preload")"_sr);
573 assert_size(0, ==, res.size());
574 }
575 {
576 // preload in relation-types list but there is trailing white
577 // space.
578 auto res = http2::parse_link_header(R"(<url>; rel="preload ")"_sr);
579 assert_size(0, ==, res.size());
580 }
581 {
582 // backslash escaped characters in quoted-string
583 auto res = http2::parse_link_header(
584 R"(<url>; rel=preload; title="foo\"baz\"bar")"_sr);
585 assert_size(1, ==, res.size());
586 assert_stdsv_equal("url"sv, res[0].uri);
587 }
588 {
589 // anchor="" is acceptable
590 auto res = http2::parse_link_header(R"(<url>; rel=preload; anchor="")"_sr);
591 assert_size(1, ==, res.size());
592 assert_stdsv_equal("url"sv, res[0].uri);
593 }
594 {
595 // With anchor="#foo", url should be ignored
596 auto res =
597 http2::parse_link_header(R"(<url>; rel=preload; anchor="#foo")"_sr);
598 assert_size(0, ==, res.size());
599 }
600 {
601 // With anchor=f, url should be ignored
602 auto res = http2::parse_link_header("<url>; rel=preload; anchor=f"_sr);
603 assert_size(0, ==, res.size());
604 }
605 {
606 // First url is ignored With anchor="#foo", but url should be
607 // accepted.
608 auto res = http2::parse_link_header(
609 R"(<url>; rel=preload; anchor="#foo", <url2>; rel=preload)"_sr);
610 assert_size(1, ==, res.size());
611 assert_stdsv_equal("url2"sv, res[0].uri);
612 }
613 {
614 // With loadpolicy="next", url should be ignored
615 auto res =
616 http2::parse_link_header(R"(<url>; rel=preload; loadpolicy="next")"_sr);
617 assert_size(0, ==, res.size());
618 }
619 {
620 // url should be picked up if empty loadpolicy is specified
621 auto res =
622 http2::parse_link_header(R"(<url>; rel=preload; loadpolicy="")"_sr);
623 assert_size(1, ==, res.size());
624 assert_stdsv_equal("url"sv, res[0].uri);
625 }
626 {
627 // case-insensitive match
628 auto res = http2::parse_link_header(
629 R"(<url>; rel=preload; ANCHOR="#foo", <url2>; )"
630 R"(REL=PRELOAD, <url3>; REL="foo PRELOAD bar")"_sr);
631 assert_size(2, ==, res.size());
632 assert_stdsv_equal("url2"sv, res[0].uri);
633 assert_stdsv_equal("url3"sv, res[1].uri);
634 }
635 {
636 // nopush at the end of input
637 auto res = http2::parse_link_header("<url>; rel=preload; nopush"_sr);
638 assert_size(0, ==, res.size());
639 }
640 {
641 // nopush followed by ';'
642 auto res = http2::parse_link_header("<url>; rel=preload; nopush; foo"_sr);
643 assert_size(0, ==, res.size());
644 }
645 {
646 // nopush followed by ','
647 auto res = http2::parse_link_header("<url>; nopush; rel=preload"_sr);
648 assert_size(0, ==, res.size());
649 }
650 {
651 // string whose prefix is nopush
652 auto res = http2::parse_link_header("<url>; nopushyes; rel=preload"_sr);
653 assert_size(1, ==, res.size());
654 assert_stdsv_equal("url"sv, res[0].uri);
655 }
656 {
657 // rel=preload twice
658 auto res = http2::parse_link_header("<url>; rel=preload; rel=preload"_sr);
659 assert_size(1, ==, res.size());
660 assert_stdsv_equal("url"sv, res[0].uri);
661 }
662 }
663
664 void test_http2_path_join(void) {
665 {
666 auto base = "/"_sr;
667 auto rel = "/"_sr;
668 assert_stdstring_equal(
669 "/", http2::path_join(base, StringRef{}, rel, StringRef{}));
670 }
671 {
672 auto base = "/"_sr;
673 auto rel = "/alpha"_sr;
674 assert_stdstring_equal(
675 "/alpha", http2::path_join(base, StringRef{}, rel, StringRef{}));
676 }
677 {
678 // rel ends with trailing '/'
679 auto base = "/"_sr;
680 auto rel = "/alpha/"_sr;
681 assert_stdstring_equal(
682 "/alpha/", http2::path_join(base, StringRef{}, rel, StringRef{}));
683 }
684 {
685 // rel contains multiple components
686 auto base = "/"_sr;
687 auto rel = "/alpha/bravo"_sr;
688 assert_stdstring_equal(
689 "/alpha/bravo", http2::path_join(base, StringRef{}, rel, StringRef{}));
690 }
691 {
692 // rel is relative
693 auto base = "/"_sr;
694 auto rel = "alpha/bravo"_sr;
695 assert_stdstring_equal(
696 "/alpha/bravo", http2::path_join(base, StringRef{}, rel, StringRef{}));
697 }
698 {
699 // rel is relative and base ends without /, which means it refers
700 // to file.
701 auto base = "/alpha"_sr;
702 auto rel = "bravo/charlie"_sr;
703 assert_stdstring_equal(
704 "/bravo/charlie",
705 http2::path_join(base, StringRef{}, rel, StringRef{}));
706 }
707 {
708 // rel contains repeated '/'s
709 auto base = "/"_sr;
710 auto rel = "/alpha/////bravo/////"_sr;
711 assert_stdstring_equal(
712 "/alpha/bravo/", http2::path_join(base, StringRef{}, rel, StringRef{}));
713 }
714 {
715 // base ends with '/', so '..' eats 'bravo'
716 auto base = "/alpha/bravo/"_sr;
717 auto rel = "../charlie/delta"_sr;
718 assert_stdstring_equal(
719 "/alpha/charlie/delta",
720 http2::path_join(base, StringRef{}, rel, StringRef{}));
721 }
722 {
723 // base does not end with '/', so '..' eats 'alpha/bravo'
724 auto base = "/alpha/bravo"_sr;
725 auto rel = "../charlie"_sr;
726 assert_stdstring_equal(
727 "/charlie", http2::path_join(base, StringRef{}, rel, StringRef{}));
728 }
729 {
730 // 'charlie' is eaten by following '..'
731 auto base = "/alpha/bravo/"_sr;
732 auto rel = "../charlie/../delta"_sr;
733 assert_stdstring_equal(
734 "/alpha/delta", http2::path_join(base, StringRef{}, rel, StringRef{}));
735 }
736 {
737 // excessive '..' results in '/'
738 auto base = "/alpha/bravo/"_sr;
739 auto rel = "../../../"_sr;
740 assert_stdstring_equal(
741 "/", http2::path_join(base, StringRef{}, rel, StringRef{}));
742 }
743 {
744 // excessive '..' and path component
745 auto base = "/alpha/bravo/"_sr;
746 auto rel = "../../../charlie"_sr;
747 assert_stdstring_equal(
748 "/charlie", http2::path_join(base, StringRef{}, rel, StringRef{}));
749 }
750 {
751 // rel ends with '..'
752 auto base = "/alpha/bravo/"_sr;
753 auto rel = "charlie/.."_sr;
754 assert_stdstring_equal(
755 "/alpha/bravo/", http2::path_join(base, StringRef{}, rel, StringRef{}));
756 }
757 {
758 // base empty and rel contains '..'
759 auto base = StringRef{};
760 auto rel = "charlie/.."_sr;
761 assert_stdstring_equal(
762 "/", http2::path_join(base, StringRef{}, rel, StringRef{}));
763 }
764 {
765 // '.' is ignored
766 auto base = "/"_sr;
767 auto rel = "charlie/././././delta"_sr;
768 assert_stdstring_equal(
769 "/charlie/delta",
770 http2::path_join(base, StringRef{}, rel, StringRef{}));
771 }
772 {
773 // trailing '.' is ignored
774 auto base = "/"_sr;
775 auto rel = "charlie/."_sr;
776 assert_stdstring_equal(
777 "/charlie/", http2::path_join(base, StringRef{}, rel, StringRef{}));
778 }
779 {
780 // query
781 auto base = "/"_sr;
782 auto rel = "/"_sr;
783 auto relq = "q"_sr;
784 assert_stdstring_equal("/?q",
785 http2::path_join(base, StringRef{}, rel, relq));
786 }
787 {
788 // empty rel and query
789 auto base = "/alpha"_sr;
790 auto rel = StringRef{};
791 auto relq = "q"_sr;
792 assert_stdstring_equal("/alpha?q",
793 http2::path_join(base, StringRef{}, rel, relq));
794 }
795 {
796 // both rel and query are empty
797 auto base = "/alpha"_sr;
798 auto baseq = "r"_sr;
799 auto rel = StringRef{};
800 auto relq = StringRef{};
801 assert_stdstring_equal("/alpha?r",
802 http2::path_join(base, baseq, rel, relq));
803 }
804 {
805 // empty base
806 auto base = StringRef{};
807 auto rel = "/alpha"_sr;
808 assert_stdstring_equal(
809 "/alpha", http2::path_join(base, StringRef{}, rel, StringRef{}));
810 }
811 {
812 // everything is empty
813 assert_stdstring_equal("/", http2::path_join(StringRef{}, StringRef{},
814 StringRef{}, StringRef{}));
815 }
816 {
817 // only baseq is not empty
818 auto base = StringRef{};
819 auto baseq = "r"_sr;
820 auto rel = StringRef{};
821 assert_stdstring_equal("/?r",
822 http2::path_join(base, baseq, rel, StringRef{}));
823 }
824 {
825 // path starts with multiple '/'s.
826 auto base = StringRef{};
827 auto baseq = StringRef{};
828 auto rel = "//alpha//bravo"_sr;
829 auto relq = "charlie"_sr;
830 assert_stdstring_equal("/alpha/bravo?charlie",
831 http2::path_join(base, baseq, rel, relq));
832 }
833 // Test cases from RFC 3986, section 5.4.
834 constexpr auto base = "/b/c/d;p"_sr;
835 constexpr auto baseq = "q"_sr;
836 {
837 auto rel = "g"_sr;
838 auto relq = StringRef{};
839 assert_stdstring_equal("/b/c/g", http2::path_join(base, baseq, rel, relq));
840 }
841 {
842 auto rel = "./g"_sr;
843 auto relq = StringRef{};
844 assert_stdstring_equal("/b/c/g", http2::path_join(base, baseq, rel, relq));
845 }
846 {
847 auto rel = "g/"_sr;
848 auto relq = StringRef{};
849 assert_stdstring_equal("/b/c/g/", http2::path_join(base, baseq, rel, relq));
850 }
851 {
852 auto rel = "/g"_sr;
853 auto relq = StringRef{};
854 assert_stdstring_equal("/g", http2::path_join(base, baseq, rel, relq));
855 }
856 {
857 auto rel = StringRef{};
858 auto relq = "y"_sr;
859 assert_stdstring_equal("/b/c/d;p?y",
860 http2::path_join(base, baseq, rel, relq));
861 }
862 {
863 auto rel = "g"_sr;
864 auto relq = "y"_sr;
865 assert_stdstring_equal("/b/c/g?y",
866 http2::path_join(base, baseq, rel, relq));
867 }
868 {
869 auto rel = ";x"_sr;
870 auto relq = StringRef{};
871 assert_stdstring_equal("/b/c/;x", http2::path_join(base, baseq, rel, relq));
872 }
873 {
874 auto rel = "g;x"_sr;
875 auto relq = StringRef{};
876 assert_stdstring_equal("/b/c/g;x",
877 http2::path_join(base, baseq, rel, relq));
878 }
879 {
880 auto rel = "g;x"_sr;
881 auto relq = "y"_sr;
882 assert_stdstring_equal("/b/c/g;x?y",
883 http2::path_join(base, baseq, rel, relq));
884 }
885 {
886 auto rel = StringRef{};
887 auto relq = StringRef{};
888 assert_stdstring_equal("/b/c/d;p?q",
889 http2::path_join(base, baseq, rel, relq));
890 }
891 {
892 auto rel = "."_sr;
893 auto relq = StringRef{};
894 assert_stdstring_equal("/b/c/", http2::path_join(base, baseq, rel, relq));
895 }
896 {
897 auto rel = "./"_sr;
898 auto relq = StringRef{};
899 assert_stdstring_equal("/b/c/", http2::path_join(base, baseq, rel, relq));
900 }
901 {
902 auto rel = ".."_sr;
903 auto relq = StringRef{};
904 assert_stdstring_equal("/b/", http2::path_join(base, baseq, rel, relq));
905 }
906 {
907 auto rel = "../"_sr;
908 auto relq = StringRef{};
909 assert_stdstring_equal("/b/", http2::path_join(base, baseq, rel, relq));
910 }
911 {
912 auto rel = "../g"_sr;
913 auto relq = StringRef{};
914 assert_stdstring_equal("/b/g", http2::path_join(base, baseq, rel, relq));
915 }
916 {
917 auto rel = "../.."_sr;
918 auto relq = StringRef{};
919 assert_stdstring_equal("/", http2::path_join(base, baseq, rel, relq));
920 }
921 {
922 auto rel = "../../"_sr;
923 auto relq = StringRef{};
924 assert_stdstring_equal("/", http2::path_join(base, baseq, rel, relq));
925 }
926 {
927 auto rel = "../../g"_sr;
928 auto relq = StringRef{};
929 assert_stdstring_equal("/g", http2::path_join(base, baseq, rel, relq));
930 }
931 {
932 auto rel = "../../../g"_sr;
933 auto relq = StringRef{};
934 assert_stdstring_equal("/g", http2::path_join(base, baseq, rel, relq));
935 }
936 {
937 auto rel = "../../../../g"_sr;
938 auto relq = StringRef{};
939 assert_stdstring_equal("/g", http2::path_join(base, baseq, rel, relq));
940 }
941 {
942 auto rel = "/./g"_sr;
943 auto relq = StringRef{};
944 assert_stdstring_equal("/g", http2::path_join(base, baseq, rel, relq));
945 }
946 {
947 auto rel = "/../g"_sr;
948 auto relq = StringRef{};
949 assert_stdstring_equal("/g", http2::path_join(base, baseq, rel, relq));
950 }
951 {
952 auto rel = "g."_sr;
953 auto relq = StringRef{};
954 assert_stdstring_equal("/b/c/g.", http2::path_join(base, baseq, rel, relq));
955 }
956 {
957 auto rel = ".g"_sr;
958 auto relq = StringRef{};
959 assert_stdstring_equal("/b/c/.g", http2::path_join(base, baseq, rel, relq));
960 }
961 {
962 auto rel = "g.."_sr;
963 auto relq = StringRef{};
964 assert_stdstring_equal("/b/c/g..",
965 http2::path_join(base, baseq, rel, relq));
966 }
967 {
968 auto rel = "..g"_sr;
969 auto relq = StringRef{};
970 assert_stdstring_equal("/b/c/..g",
971 http2::path_join(base, baseq, rel, relq));
972 }
973 {
974 auto rel = "./../g"_sr;
975 auto relq = StringRef{};
976 assert_stdstring_equal("/b/g", http2::path_join(base, baseq, rel, relq));
977 }
978 {
979 auto rel = "./g/."_sr;
980 auto relq = StringRef{};
981 assert_stdstring_equal("/b/c/g/", http2::path_join(base, baseq, rel, relq));
982 }
983 {
984 auto rel = "g/./h"_sr;
985 auto relq = StringRef{};
986 assert_stdstring_equal("/b/c/g/h",
987 http2::path_join(base, baseq, rel, relq));
988 }
989 {
990 auto rel = "g/../h"_sr;
991 auto relq = StringRef{};
992 assert_stdstring_equal("/b/c/h", http2::path_join(base, baseq, rel, relq));
993 }
994 {
995 auto rel = "g;x=1/./y"_sr;
996 auto relq = StringRef{};
997 assert_stdstring_equal("/b/c/g;x=1/y",
998 http2::path_join(base, baseq, rel, relq));
999 }
1000 {
1001 auto rel = "g;x=1/../y"_sr;
1002 auto relq = StringRef{};
1003 assert_stdstring_equal("/b/c/y", http2::path_join(base, baseq, rel, relq));
1004 }
1005 }
1006
test_http2_normalize_path(void)1007 void test_http2_normalize_path(void) {
1008 assert_stdstring_equal(
1009 "/alpha/charlie",
1010 http2::normalize_path("/alpha/bravo/../charlie"_sr, StringRef{}));
1011
1012 assert_stdstring_equal(
1013 "/alpha", http2::normalize_path("/a%6c%70%68%61"_sr, StringRef{}));
1014
1015 assert_stdstring_equal("/alpha%2F%3A",
1016 http2::normalize_path("/alpha%2f%3a"_sr, StringRef{}));
1017
1018 assert_stdstring_equal("/%2F", http2::normalize_path("%2f"_sr, StringRef{}));
1019
1020 assert_stdstring_equal("/%f", http2::normalize_path("%f"_sr, StringRef{}));
1021
1022 assert_stdstring_equal("/%", http2::normalize_path("%"_sr, StringRef{}));
1023
1024 assert_stdstring_equal("/", http2::normalize_path(StringRef{}, StringRef{}));
1025
1026 assert_stdstring_equal("/alpha?bravo",
1027 http2::normalize_path("/alpha"_sr, "bravo"_sr));
1028 }
1029
test_http2_rewrite_clean_path(void)1030 void test_http2_rewrite_clean_path(void) {
1031 BlockAllocator balloc(4096, 4096);
1032
1033 // unreserved characters
1034 assert_stdsv_equal("/alpha/bravo/"sv,
1035 http2::rewrite_clean_path(balloc, "/alpha/%62ravo/"_sr));
1036
1037 // percent-encoding is converted to upper case.
1038 assert_stdsv_equal("/delta%3A"sv,
1039 http2::rewrite_clean_path(balloc, "/delta%3a"_sr));
1040
1041 // path component is normalized before matching
1042 assert_stdsv_equal("/alpha/bravo/"sv,
1043 http2::rewrite_clean_path(
1044 balloc, "/alpha/charlie/%2e././bravo/delta/.."_sr));
1045
1046 assert_stdsv_equal("alpha%3a"sv,
1047 http2::rewrite_clean_path(balloc, "alpha%3a"_sr));
1048
1049 assert_stdsv_equal(""sv, http2::rewrite_clean_path(balloc, StringRef{}));
1050
1051 assert_stdsv_equal("/alpha?bravo"sv,
1052 http2::rewrite_clean_path(balloc, "//alpha?bravo"_sr));
1053 }
1054
test_http2_get_pure_path_component(void)1055 void test_http2_get_pure_path_component(void) {
1056 assert_stdsv_equal("/"sv, http2::get_pure_path_component("/"_sr));
1057
1058 assert_stdsv_equal("/foo"sv, http2::get_pure_path_component("/foo"_sr));
1059
1060 assert_stdsv_equal(
1061 "/bar"sv, http2::get_pure_path_component("https://example.org/bar"_sr));
1062
1063 assert_stdsv_equal("/alpha"sv, http2::get_pure_path_component(
1064 "https://example.org/alpha?q=a"_sr));
1065
1066 assert_stdsv_equal("/bravo"sv,
1067 http2::get_pure_path_component(
1068 "https://example.org/bravo?q=a#fragment"_sr));
1069
1070 assert_stdsv_equal(""sv, http2::get_pure_path_component("\x01\x02"_sr));
1071 }
1072
test_http2_construct_push_component(void)1073 void test_http2_construct_push_component(void) {
1074 BlockAllocator balloc(4096, 4096);
1075 StringRef base, uri;
1076 StringRef scheme, authority, path;
1077
1078 base = "/b/"_sr;
1079 uri = "https://example.org/foo"_sr;
1080
1081 assert_int(0, ==,
1082 http2::construct_push_component(balloc, scheme, authority, path,
1083 base, uri));
1084 assert_stdsv_equal("https"sv, scheme);
1085 assert_stdsv_equal("example.org"sv, authority);
1086 assert_stdsv_equal("/foo"sv, path);
1087
1088 scheme = StringRef{};
1089 authority = StringRef{};
1090 path = StringRef{};
1091
1092 uri = "/foo/bar?q=a"_sr;
1093
1094 assert_int(0, ==,
1095 http2::construct_push_component(balloc, scheme, authority, path,
1096 base, uri));
1097 assert_stdsv_equal(""sv, scheme);
1098 assert_stdsv_equal(""sv, authority);
1099 assert_stdsv_equal("/foo/bar?q=a"sv, path);
1100
1101 scheme = StringRef{};
1102 authority = StringRef{};
1103 path = StringRef{};
1104
1105 uri = "foo/../bar?q=a"_sr;
1106
1107 assert_int(0, ==,
1108 http2::construct_push_component(balloc, scheme, authority, path,
1109 base, uri));
1110 assert_stdsv_equal(""sv, scheme);
1111 assert_stdsv_equal(""sv, authority);
1112 assert_stdsv_equal("/b/bar?q=a"sv, path);
1113
1114 scheme = StringRef{};
1115 authority = StringRef{};
1116 path = StringRef{};
1117
1118 uri = StringRef{};
1119
1120 assert_int(-1, ==,
1121 http2::construct_push_component(balloc, scheme, authority, path,
1122 base, uri));
1123 scheme = StringRef{};
1124 authority = StringRef{};
1125 path = StringRef{};
1126
1127 uri = "?q=a"_sr;
1128
1129 assert_int(0, ==,
1130 http2::construct_push_component(balloc, scheme, authority, path,
1131 base, uri));
1132 assert_stdsv_equal(""sv, scheme);
1133 assert_stdsv_equal(""sv, authority);
1134 assert_stdsv_equal("/b/?q=a"sv, path);
1135 }
1136
test_http2_contains_trailers(void)1137 void test_http2_contains_trailers(void) {
1138 assert_false(http2::contains_trailers(""_sr));
1139 assert_true(http2::contains_trailers("trailers"_sr));
1140 // Match must be case-insensitive.
1141 assert_true(http2::contains_trailers("TRAILERS"_sr));
1142 assert_false(http2::contains_trailers("trailer"_sr));
1143 assert_false(http2::contains_trailers("trailers 3"_sr));
1144 assert_true(http2::contains_trailers("trailers,"_sr));
1145 assert_true(http2::contains_trailers("trailers,foo"_sr));
1146 assert_true(http2::contains_trailers("foo,trailers"_sr));
1147 assert_true(http2::contains_trailers("foo,trailers,bar"_sr));
1148 assert_true(http2::contains_trailers("foo, trailers ,bar"_sr));
1149 assert_true(http2::contains_trailers(",trailers"_sr));
1150 }
1151
test_http2_check_transfer_encoding(void)1152 void test_http2_check_transfer_encoding(void) {
1153 assert_true(http2::check_transfer_encoding("chunked"_sr));
1154 assert_true(http2::check_transfer_encoding("foo,chunked"_sr));
1155 assert_true(http2::check_transfer_encoding("foo, chunked"_sr));
1156 assert_true(http2::check_transfer_encoding("foo , chunked"_sr));
1157 assert_true(http2::check_transfer_encoding("chunked;foo=bar"_sr));
1158 assert_true(http2::check_transfer_encoding("chunked ; foo=bar"_sr));
1159 assert_true(http2::check_transfer_encoding(R"(chunked;foo="bar")"_sr));
1160 assert_true(
1161 http2::check_transfer_encoding(R"(chunked;foo="\bar\"";FOO=BAR)"_sr));
1162 assert_true(http2::check_transfer_encoding(R"(chunked;foo="")"_sr));
1163 assert_true(http2::check_transfer_encoding(R"(chunked;foo="bar" , gzip)"_sr));
1164
1165 assert_false(http2::check_transfer_encoding(StringRef{}));
1166 assert_false(http2::check_transfer_encoding(",chunked"_sr));
1167 assert_false(http2::check_transfer_encoding("chunked,"_sr));
1168 assert_false(http2::check_transfer_encoding("chunked, "_sr));
1169 assert_false(http2::check_transfer_encoding("foo,,chunked"_sr));
1170 assert_false(http2::check_transfer_encoding("chunked;foo"_sr));
1171 assert_false(http2::check_transfer_encoding("chunked;"_sr));
1172 assert_false(http2::check_transfer_encoding("chunked;foo=bar;"_sr));
1173 assert_false(http2::check_transfer_encoding("chunked;?=bar"_sr));
1174 assert_false(http2::check_transfer_encoding("chunked;=bar"_sr));
1175 assert_false(http2::check_transfer_encoding("chunked;;"_sr));
1176 assert_false(http2::check_transfer_encoding("chunked?"_sr));
1177 assert_false(http2::check_transfer_encoding(","_sr));
1178 assert_false(http2::check_transfer_encoding(" "_sr));
1179 assert_false(http2::check_transfer_encoding(";"_sr));
1180 assert_false(http2::check_transfer_encoding("\""_sr));
1181 assert_false(http2::check_transfer_encoding(R"(chunked;foo="bar)"_sr));
1182 assert_false(http2::check_transfer_encoding(R"(chunked;foo="bar\)"_sr));
1183 assert_false(http2::check_transfer_encoding(R"(chunked;foo="bar\)"
1184 "\x0a"
1185 R"(")"_sr));
1186 assert_false(http2::check_transfer_encoding(R"(chunked;foo=")"
1187 "\x0a"
1188 R"(")"_sr));
1189 assert_false(http2::check_transfer_encoding(R"(chunked;foo="bar",,gzip)"_sr));
1190 }
1191
1192 } // namespace shrpx
1193