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

Method testContentLengthField

test/beast/http/basic_parser.cpp:688–731  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

686 }
687
688 void
689 testContentLengthField()
690 {
691 using P = test_parser<true>;
692 auto const c = [](std::string const& s)
693 { return "GET / HTTP/1.1\r\nContent-Length: " + s + "\r\n"; };
694 auto const m = [](std::string const& s)
695 { return "GET / HTTP/1.1\r\n" + s + "\r\n"; };
696 auto const check =
697 [&](std::string const& s, std::uint64_t v)
698 {
699 parsegrind<P>(c(s),
700 [&](P const& p)
701 {
702 BEAST_EXPECT(p.content_length());
703 BEAST_EXPECT(p.content_length() && *p.content_length() == v);
704 }, true);
705 };
706
707 check("0\r\n", 0);
708 check("00\r\n", 0);
709 check("1\r\n", 1);
710 check("01\r\n", 1);
711 check("9\r\n", 9);
712 check("42 \r\n", 42);
713 check("42\t\r\n", 42);
714 check("42 \t \r\n", 42);
715 check("42\r\n \t \r\n", 42);
716
717 parsegrind<P>(m("Content-LengtX: 0\r\n"), expect_flags{*this, 0});
718 parsegrind<P>(m("Content-Lengths: many\r\n"), expect_flags{*this, 0});
719 parsegrind<P>(m("Content: full\r\n"), expect_flags{*this, 0});
720 parsegrind<P>(m("Content-Length: 0\r\n"
721 "Content-Length: 0\r\n"), expect_flags{*this, 0});
722
723 failgrind<P>(c("\r\n"), error::bad_content_length);
724 failgrind<P>(c("18446744073709551616\r\n"), error::bad_content_length);
725 failgrind<P>(c("0 0\r\n"), error::bad_content_length);
726 failgrind<P>(c("0 1\r\n"), error::bad_content_length);
727 failgrind<P>(c(",\r\n"), error::bad_content_length);
728 failgrind<P>(c("0,\r\n"), error::bad_content_length);
729 failgrind<P>(m("Content-Length: 0\r\n"
730 "Content-Length: 100\r\n"), error::multiple_content_length);
731 }
732
733 void
734 testTransferEncodingField()

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected