MCPcopy Create free account
hub / github.com/boostorg/beast / testIssue1880

Method testIssue1880

test/beast/http/parser.cpp:473–530  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

471 }
472
473 void
474 testIssue1880()
475 {
476 // A user raised the issue that multiple Content-Length fields and
477 // values are permissible provided all values are the same.
478 // See rfc7230 section-3.3.2
479 // https://tools.ietf.org/html/rfc7230#section-3.3.2
480 // Credit: Dimitry Bulsunov
481
482 auto checkPass = [&](std::string const& message)
483 {
484 response_parser<string_body> parser;
485 error_code ec;
486 parser.put(net::buffer(message), ec);
487 BEAST_EXPECTS(!ec.failed(), ec.message());
488 };
489
490 auto checkFail = [&](std::string const& message)
491 {
492 response_parser<string_body> parser;
493 error_code ec;
494 parser.put(net::buffer(message), ec);
495 BEAST_EXPECTS(ec == error::multiple_content_length, ec.message());
496 };
497
498 // multiple contents lengths the same
499 checkPass(
500 "HTTP/1.1 200 OK\r\n"
501 "Content-Length: 0\r\n"
502 "Content-Length: 0\r\n"
503 "\r\n");
504
505 // multiple contents lengths different
506 checkFail(
507 "HTTP/1.1 200 OK\r\n"
508 "Content-Length: 0\r\n"
509 "Content-Length: 1\r\n"
510 "\r\n");
511
512 // multiple content in same header
513 checkPass(
514 "HTTP/1.1 200 OK\r\n"
515 "Content-Length: 0, 0, 0\r\n"
516 "\r\n");
517
518 // multiple content in same header but mismatch (case 1)
519 checkFail(
520 "HTTP/1.1 200 OK\r\n"
521 "Content-Length: 0, 0, 1\r\n"
522 "\r\n");
523
524 // multiple content in same header but mismatch (case 2)
525 checkFail(
526 "HTTP/1.1 200 OK\r\n"
527 "Content-Length: 0, 0, 0\r\n"
528 "Content-Length: 1\r\n"
529 "\r\n");
530 }

Callers

nothing calls this directly

Calls 3

messageMethod · 0.80
putMethod · 0.45
failedMethod · 0.45

Tested by

no test coverage detected