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

Method testReadSomeHeader

test/beast/http/read.cpp:587–669  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

585#endif
586
587 void testReadSomeHeader(net::yield_context yield)
588 {
589 std::string hdr =
590 "GET /foo HTTP/1.1" "\r\n"
591 "Connection: Keep-Alive" "\r\n"
592 "Content-Length: 6"
593 "\r\n"
594 "\r\n";
595 std::string body =
596 "Hello!";
597
598 {
599 // bytes_transferred returns length of header
600 request_parser<string_body> p;
601 test::stream s(ioc_);
602
603 s.append(string_view(hdr));
604 s.append(string_view(body));
605 flat_buffer fb;
606 error_code ec;
607 auto bt = async_read_header(s, fb, p, yield[ec]);
608 BEAST_EXPECTS(!ec, ec.message());
609 BEAST_EXPECT(bt == hdr.size());
610
611 // next read should be zero-size, success
612 bt = async_read_header(s, fb, p, yield[ec]);
613 BEAST_EXPECTS(!ec, ec.message());
614 BEAST_EXPECTS(bt == 0, std::to_string(0));
615 }
616
617 {
618 // incomplete header consumes all parsable header bytes
619 request_parser<string_body> p;
620 test::stream s(ioc_);
621
622 s.append(hdr.substr(0, hdr.size() - 1));
623 s.close();
624 flat_buffer fb;
625 error_code ec;
626 auto bt = async_read_header(s, fb, p, yield[ec]);
627 BEAST_EXPECTS(ec == error::partial_message, ec.message());
628 BEAST_EXPECTS(bt + fb.size() == hdr.size() - 1,
629 std::to_string(bt + fb.size()) +
630 " expected " +
631 std::to_string(hdr.size() - 1));
632 }
633
634 {
635 // read consumes and reports correct number of bytes
636 request_parser<string_body> p;
637 test::stream s(ioc_);
638
639 s.append(hdr);
640 s.append(body);
641 s.append(hdr);
642 s.append(body);
643 s.append(hdr);
644 s.append(body);

Callers

nothing calls this directly

Calls 7

async_read_headerFunction · 0.85
async_read_someFunction · 0.85
read_headerFunction · 0.85
messageMethod · 0.80
async_readFunction · 0.50
sizeMethod · 0.45
closeMethod · 0.45

Tested by

no test coverage detected