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, \
44 sizeof(V) - 1, 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}, StringRef{req_authority},
261 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", http2::path_join(base, StringRef{}, rel, StringRef{}));
705 }
706 {
707 // rel contains repeated '/'s
708 auto base = "/"_sr;
709 auto rel = "/alpha/////bravo/////"_sr;
710 assert_stdstring_equal(
711 "/alpha/bravo/", http2::path_join(base, StringRef{}, rel, StringRef{}));
712 }
713 {
714 // base ends with '/', so '..' eats 'bravo'
715 auto base = "/alpha/bravo/"_sr;
716 auto rel = "../charlie/delta"_sr;
717 assert_stdstring_equal(
718 "/alpha/charlie/delta",
719 http2::path_join(base, StringRef{}, rel, StringRef{}));
720 }
721 {
722 // base does not end with '/', so '..' eats 'alpha/bravo'
723 auto base = "/alpha/bravo"_sr;
724 auto rel = "../charlie"_sr;
725 assert_stdstring_equal(
726 "/charlie", http2::path_join(base, StringRef{}, rel, StringRef{}));
727 }
728 {
729 // 'charlie' is eaten by following '..'
730 auto base = "/alpha/bravo/"_sr;
731 auto rel = "../charlie/../delta"_sr;
732 assert_stdstring_equal(
733 "/alpha/delta", http2::path_join(base, StringRef{}, rel, StringRef{}));
734 }
735 {
736 // excessive '..' results in '/'
737 auto base = "/alpha/bravo/"_sr;
738 auto rel = "../../../"_sr;
739 assert_stdstring_equal(
740 "/", http2::path_join(base, StringRef{}, rel, StringRef{}));
741 }
742 {
743 // excessive '..' and path component
744 auto base = "/alpha/bravo/"_sr;
745 auto rel = "../../../charlie"_sr;
746 assert_stdstring_equal(
747 "/charlie", http2::path_join(base, StringRef{}, rel, StringRef{}));
748 }
749 {
750 // rel ends with '..'
751 auto base = "/alpha/bravo/"_sr;
752 auto rel = "charlie/.."_sr;
753 assert_stdstring_equal(
754 "/alpha/bravo/", http2::path_join(base, StringRef{}, rel, StringRef{}));
755 }
756 {
757 // base empty and rel contains '..'
758 auto base = StringRef{};
759 auto rel = "charlie/.."_sr;
760 assert_stdstring_equal(
761 "/", http2::path_join(base, StringRef{}, rel, StringRef{}));
762 }
763 {
764 // '.' is ignored
765 auto base = "/"_sr;
766 auto rel = "charlie/././././delta"_sr;
767 assert_stdstring_equal(
768 "/charlie/delta", http2::path_join(base, StringRef{}, rel, StringRef{}));
769 }
770 {
771 // trailing '.' is ignored
772 auto base = "/"_sr;
773 auto rel = "charlie/."_sr;
774 assert_stdstring_equal(
775 "/charlie/", http2::path_join(base, StringRef{}, rel, StringRef{}));
776 }
777 {
778 // query
779 auto base = "/"_sr;
780 auto rel = "/"_sr;
781 auto relq = "q"_sr;
782 assert_stdstring_equal("/?q",
783 http2::path_join(base, StringRef{}, rel, relq));
784 }
785 {
786 // empty rel and query
787 auto base = "/alpha"_sr;
788 auto rel = StringRef{};
789 auto relq = "q"_sr;
790 assert_stdstring_equal("/alpha?q",
791 http2::path_join(base, StringRef{}, rel, relq));
792 }
793 {
794 // both rel and query are empty
795 auto base = "/alpha"_sr;
796 auto baseq = "r"_sr;
797 auto rel = StringRef{};
798 auto relq = StringRef{};
799 assert_stdstring_equal("/alpha?r",
800 http2::path_join(base, baseq, rel, relq));
801 }
802 {
803 // empty base
804 auto base = StringRef{};
805 auto rel = "/alpha"_sr;
806 assert_stdstring_equal(
807 "/alpha", http2::path_join(base, StringRef{}, rel, StringRef{}));
808 }
809 {
810 // everything is empty
811 assert_stdstring_equal("/", http2::path_join(StringRef{}, StringRef{},
812 StringRef{}, StringRef{}));
813 }
814 {
815 // only baseq is not empty
816 auto base = StringRef{};
817 auto baseq = "r"_sr;
818 auto rel = StringRef{};
819 assert_stdstring_equal("/?r",
820 http2::path_join(base, baseq, rel, StringRef{}));
821 }
822 {
823 // path starts with multiple '/'s.
824 auto base = StringRef{};
825 auto baseq = StringRef{};
826 auto rel = "//alpha//bravo"_sr;
827 auto relq = "charlie"_sr;
828 assert_stdstring_equal("/alpha/bravo?charlie",
829 http2::path_join(base, baseq, rel, relq));
830 }
831 // Test cases from RFC 3986, section 5.4.
832 constexpr auto base = "/b/c/d;p"_sr;
833 constexpr auto baseq = "q"_sr;
834 {
835 auto rel = "g"_sr;
836 auto relq = StringRef{};
837 assert_stdstring_equal("/b/c/g", http2::path_join(base, baseq, rel, relq));
838 }
839 {
840 auto rel = "./g"_sr;
841 auto relq = StringRef{};
842 assert_stdstring_equal("/b/c/g", http2::path_join(base, baseq, rel, relq));
843 }
844 {
845 auto rel = "g/"_sr;
846 auto relq = StringRef{};
847 assert_stdstring_equal("/b/c/g/", http2::path_join(base, baseq, rel, relq));
848 }
849 {
850 auto rel = "/g"_sr;
851 auto relq = StringRef{};
852 assert_stdstring_equal("/g", http2::path_join(base, baseq, rel, relq));
853 }
854 {
855 auto rel = StringRef{};
856 auto relq = "y"_sr;
857 assert_stdstring_equal("/b/c/d;p?y",
858 http2::path_join(base, baseq, rel, relq));
859 }
860 {
861 auto rel = "g"_sr;
862 auto relq = "y"_sr;
863 assert_stdstring_equal("/b/c/g?y",
864 http2::path_join(base, baseq, rel, relq));
865 }
866 {
867 auto rel = ";x"_sr;
868 auto relq = StringRef{};
869 assert_stdstring_equal("/b/c/;x", http2::path_join(base, baseq, rel, relq));
870 }
871 {
872 auto rel = "g;x"_sr;
873 auto relq = StringRef{};
874 assert_stdstring_equal("/b/c/g;x",
875 http2::path_join(base, baseq, rel, relq));
876 }
877 {
878 auto rel = "g;x"_sr;
879 auto relq = "y"_sr;
880 assert_stdstring_equal("/b/c/g;x?y",
881 http2::path_join(base, baseq, rel, relq));
882 }
883 {
884 auto rel = StringRef{};
885 auto relq = StringRef{};
886 assert_stdstring_equal("/b/c/d;p?q",
887 http2::path_join(base, baseq, rel, relq));
888 }
889 {
890 auto rel = "."_sr;
891 auto relq = StringRef{};
892 assert_stdstring_equal("/b/c/", http2::path_join(base, baseq, rel, relq));
893 }
894 {
895 auto rel = "./"_sr;
896 auto relq = StringRef{};
897 assert_stdstring_equal("/b/c/", http2::path_join(base, baseq, rel, relq));
898 }
899 {
900 auto rel = ".."_sr;
901 auto relq = StringRef{};
902 assert_stdstring_equal("/b/", http2::path_join(base, baseq, rel, relq));
903 }
904 {
905 auto rel = "../"_sr;
906 auto relq = StringRef{};
907 assert_stdstring_equal("/b/", http2::path_join(base, baseq, rel, relq));
908 }
909 {
910 auto rel = "../g"_sr;
911 auto relq = StringRef{};
912 assert_stdstring_equal("/b/g", http2::path_join(base, baseq, rel, relq));
913 }
914 {
915 auto rel = "../.."_sr;
916 auto relq = StringRef{};
917 assert_stdstring_equal("/", http2::path_join(base, baseq, rel, relq));
918 }
919 {
920 auto rel = "../../"_sr;
921 auto relq = StringRef{};
922 assert_stdstring_equal("/", http2::path_join(base, baseq, rel, relq));
923 }
924 {
925 auto rel = "../../g"_sr;
926 auto relq = StringRef{};
927 assert_stdstring_equal("/g", http2::path_join(base, baseq, rel, relq));
928 }
929 {
930 auto rel = "../../../g"_sr;
931 auto relq = StringRef{};
932 assert_stdstring_equal("/g", http2::path_join(base, baseq, rel, relq));
933 }
934 {
935 auto rel = "../../../../g"_sr;
936 auto relq = StringRef{};
937 assert_stdstring_equal("/g", http2::path_join(base, baseq, rel, relq));
938 }
939 {
940 auto rel = "/./g"_sr;
941 auto relq = StringRef{};
942 assert_stdstring_equal("/g", http2::path_join(base, baseq, rel, relq));
943 }
944 {
945 auto rel = "/../g"_sr;
946 auto relq = StringRef{};
947 assert_stdstring_equal("/g", http2::path_join(base, baseq, rel, relq));
948 }
949 {
950 auto rel = "g."_sr;
951 auto relq = StringRef{};
952 assert_stdstring_equal("/b/c/g.", http2::path_join(base, baseq, rel, relq));
953 }
954 {
955 auto rel = ".g"_sr;
956 auto relq = StringRef{};
957 assert_stdstring_equal("/b/c/.g", http2::path_join(base, baseq, rel, relq));
958 }
959 {
960 auto rel = "g.."_sr;
961 auto relq = StringRef{};
962 assert_stdstring_equal("/b/c/g..",
963 http2::path_join(base, baseq, rel, relq));
964 }
965 {
966 auto rel = "..g"_sr;
967 auto relq = StringRef{};
968 assert_stdstring_equal("/b/c/..g",
969 http2::path_join(base, baseq, rel, relq));
970 }
971 {
972 auto rel = "./../g"_sr;
973 auto relq = StringRef{};
974 assert_stdstring_equal("/b/g", http2::path_join(base, baseq, rel, relq));
975 }
976 {
977 auto rel = "./g/."_sr;
978 auto relq = StringRef{};
979 assert_stdstring_equal("/b/c/g/", http2::path_join(base, baseq, rel, relq));
980 }
981 {
982 auto rel = "g/./h"_sr;
983 auto relq = StringRef{};
984 assert_stdstring_equal("/b/c/g/h",
985 http2::path_join(base, baseq, rel, relq));
986 }
987 {
988 auto rel = "g/../h"_sr;
989 auto relq = StringRef{};
990 assert_stdstring_equal("/b/c/h", http2::path_join(base, baseq, rel, relq));
991 }
992 {
993 auto rel = "g;x=1/./y"_sr;
994 auto relq = StringRef{};
995 assert_stdstring_equal("/b/c/g;x=1/y",
996 http2::path_join(base, baseq, rel, relq));
997 }
998 {
999 auto rel = "g;x=1/../y"_sr;
1000 auto relq = StringRef{};
1001 assert_stdstring_equal("/b/c/y", http2::path_join(base, baseq, rel, relq));
1002 }
1003 }
1004
test_http2_normalize_path(void)1005 void test_http2_normalize_path(void) {
1006 assert_stdstring_equal(
1007 "/alpha/charlie",
1008 http2::normalize_path("/alpha/bravo/../charlie"_sr, StringRef{}));
1009
1010 assert_stdstring_equal(
1011 "/alpha", http2::normalize_path("/a%6c%70%68%61"_sr, StringRef{}));
1012
1013 assert_stdstring_equal("/alpha%2F%3A",
1014 http2::normalize_path("/alpha%2f%3a"_sr, StringRef{}));
1015
1016 assert_stdstring_equal("/%2F", http2::normalize_path("%2f"_sr, StringRef{}));
1017
1018 assert_stdstring_equal("/%f", http2::normalize_path("%f"_sr, StringRef{}));
1019
1020 assert_stdstring_equal("/%", http2::normalize_path("%"_sr, StringRef{}));
1021
1022 assert_stdstring_equal("/", http2::normalize_path(StringRef{}, StringRef{}));
1023
1024 assert_stdstring_equal("/alpha?bravo",
1025 http2::normalize_path("/alpha"_sr, "bravo"_sr));
1026 }
1027
test_http2_rewrite_clean_path(void)1028 void test_http2_rewrite_clean_path(void) {
1029 BlockAllocator balloc(4096, 4096);
1030
1031 // unreserved characters
1032 assert_stdsv_equal("/alpha/bravo/"sv,
1033 http2::rewrite_clean_path(balloc, "/alpha/%62ravo/"_sr));
1034
1035 // percent-encoding is converted to upper case.
1036 assert_stdsv_equal("/delta%3A"sv,
1037 http2::rewrite_clean_path(balloc, "/delta%3a"_sr));
1038
1039 // path component is normalized before matching
1040 assert_stdsv_equal("/alpha/bravo/"sv,
1041 http2::rewrite_clean_path(
1042 balloc, "/alpha/charlie/%2e././bravo/delta/.."_sr));
1043
1044 assert_stdsv_equal("alpha%3a"sv,
1045 http2::rewrite_clean_path(balloc, "alpha%3a"_sr));
1046
1047 assert_stdsv_equal(""sv, http2::rewrite_clean_path(balloc, StringRef{}));
1048
1049 assert_stdsv_equal("/alpha?bravo"sv,
1050 http2::rewrite_clean_path(balloc, "//alpha?bravo"_sr));
1051 }
1052
test_http2_get_pure_path_component(void)1053 void test_http2_get_pure_path_component(void) {
1054 assert_stdsv_equal("/"sv, http2::get_pure_path_component("/"_sr));
1055
1056 assert_stdsv_equal("/foo"sv, http2::get_pure_path_component("/foo"_sr));
1057
1058 assert_stdsv_equal(
1059 "/bar"sv, http2::get_pure_path_component("https://example.org/bar"_sr));
1060
1061 assert_stdsv_equal("/alpha"sv, http2::get_pure_path_component(
1062 "https://example.org/alpha?q=a"_sr));
1063
1064 assert_stdsv_equal("/bravo"sv,
1065 http2::get_pure_path_component(
1066 "https://example.org/bravo?q=a#fragment"_sr));
1067
1068 assert_stdsv_equal(""sv, http2::get_pure_path_component("\x01\x02"_sr));
1069 }
1070
test_http2_construct_push_component(void)1071 void test_http2_construct_push_component(void) {
1072 BlockAllocator balloc(4096, 4096);
1073 StringRef base, uri;
1074 StringRef scheme, authority, path;
1075
1076 base = "/b/"_sr;
1077 uri = "https://example.org/foo"_sr;
1078
1079 assert_int(0, ==,
1080 http2::construct_push_component(balloc, scheme, authority, path,
1081 base, uri));
1082 assert_stdsv_equal("https"sv, scheme);
1083 assert_stdsv_equal("example.org"sv, authority);
1084 assert_stdsv_equal("/foo"sv, path);
1085
1086 scheme = StringRef{};
1087 authority = StringRef{};
1088 path = StringRef{};
1089
1090 uri = "/foo/bar?q=a"_sr;
1091
1092 assert_int(0, ==,
1093 http2::construct_push_component(balloc, scheme, authority, path,
1094 base, uri));
1095 assert_stdsv_equal(""sv, scheme);
1096 assert_stdsv_equal(""sv, authority);
1097 assert_stdsv_equal("/foo/bar?q=a"sv, path);
1098
1099 scheme = StringRef{};
1100 authority = StringRef{};
1101 path = StringRef{};
1102
1103 uri = "foo/../bar?q=a"_sr;
1104
1105 assert_int(0, ==,
1106 http2::construct_push_component(balloc, scheme, authority, path,
1107 base, uri));
1108 assert_stdsv_equal(""sv, scheme);
1109 assert_stdsv_equal(""sv, authority);
1110 assert_stdsv_equal("/b/bar?q=a"sv, path);
1111
1112 scheme = StringRef{};
1113 authority = StringRef{};
1114 path = StringRef{};
1115
1116 uri = StringRef{};
1117
1118 assert_int(-1, ==,
1119 http2::construct_push_component(balloc, scheme, authority, path,
1120 base, uri));
1121 scheme = StringRef{};
1122 authority = StringRef{};
1123 path = StringRef{};
1124
1125 uri = "?q=a"_sr;
1126
1127 assert_int(0, ==,
1128 http2::construct_push_component(balloc, scheme, authority, path,
1129 base, uri));
1130 assert_stdsv_equal(""sv, scheme);
1131 assert_stdsv_equal(""sv, authority);
1132 assert_stdsv_equal("/b/?q=a"sv, path);
1133 }
1134
test_http2_contains_trailers(void)1135 void test_http2_contains_trailers(void) {
1136 assert_false(http2::contains_trailers(""_sr));
1137 assert_true(http2::contains_trailers("trailers"_sr));
1138 // Match must be case-insensitive.
1139 assert_true(http2::contains_trailers("TRAILERS"_sr));
1140 assert_false(http2::contains_trailers("trailer"_sr));
1141 assert_false(http2::contains_trailers("trailers 3"_sr));
1142 assert_true(http2::contains_trailers("trailers,"_sr));
1143 assert_true(http2::contains_trailers("trailers,foo"_sr));
1144 assert_true(http2::contains_trailers("foo,trailers"_sr));
1145 assert_true(http2::contains_trailers("foo,trailers,bar"_sr));
1146 assert_true(http2::contains_trailers("foo, trailers ,bar"_sr));
1147 assert_true(http2::contains_trailers(",trailers"_sr));
1148 }
1149
test_http2_check_transfer_encoding(void)1150 void test_http2_check_transfer_encoding(void) {
1151 assert_true(http2::check_transfer_encoding("chunked"_sr));
1152 assert_true(http2::check_transfer_encoding("foo,chunked"_sr));
1153 assert_true(http2::check_transfer_encoding("foo, chunked"_sr));
1154 assert_true(http2::check_transfer_encoding("foo , chunked"_sr));
1155 assert_true(http2::check_transfer_encoding("chunked;foo=bar"_sr));
1156 assert_true(http2::check_transfer_encoding("chunked ; foo=bar"_sr));
1157 assert_true(http2::check_transfer_encoding(R"(chunked;foo="bar")"_sr));
1158 assert_true(
1159 http2::check_transfer_encoding(R"(chunked;foo="\bar\"";FOO=BAR)"_sr));
1160 assert_true(http2::check_transfer_encoding(R"(chunked;foo="")"_sr));
1161 assert_true(http2::check_transfer_encoding(R"(chunked;foo="bar" , gzip)"_sr));
1162
1163 assert_false(http2::check_transfer_encoding(StringRef{}));
1164 assert_false(http2::check_transfer_encoding(",chunked"_sr));
1165 assert_false(http2::check_transfer_encoding("chunked,"_sr));
1166 assert_false(http2::check_transfer_encoding("chunked, "_sr));
1167 assert_false(http2::check_transfer_encoding("foo,,chunked"_sr));
1168 assert_false(http2::check_transfer_encoding("chunked;foo"_sr));
1169 assert_false(http2::check_transfer_encoding("chunked;"_sr));
1170 assert_false(http2::check_transfer_encoding("chunked;foo=bar;"_sr));
1171 assert_false(http2::check_transfer_encoding("chunked;?=bar"_sr));
1172 assert_false(http2::check_transfer_encoding("chunked;=bar"_sr));
1173 assert_false(http2::check_transfer_encoding("chunked;;"_sr));
1174 assert_false(http2::check_transfer_encoding("chunked?"_sr));
1175 assert_false(http2::check_transfer_encoding(","_sr));
1176 assert_false(http2::check_transfer_encoding(" "_sr));
1177 assert_false(http2::check_transfer_encoding(";"_sr));
1178 assert_false(http2::check_transfer_encoding("\""_sr));
1179 assert_false(http2::check_transfer_encoding(R"(chunked;foo="bar)"_sr));
1180 assert_false(http2::check_transfer_encoding(R"(chunked;foo="bar\)"_sr));
1181 assert_false(http2::check_transfer_encoding(R"(chunked;foo="bar\)"
1182 "\x0a"
1183 R"(")"_sr));
1184 assert_false(http2::check_transfer_encoding(R"(chunked;foo=")"
1185 "\x0a"
1186 R"(")"_sr));
1187 assert_false(http2::check_transfer_encoding(R"(chunked;foo="bar",,gzip)"_sr));
1188 }
1189
1190 } // namespace shrpx
1191