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

Method testIssue1734

test/beast/http/basic_parser.cpp:1370–1456  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1368 // https://github.com/boostorg/beast/issues/1734
1369
1370 void
1371 testIssue1734()
1372 {
1373 // Ensure more than one buffer, this is to avoid an optimized path in
1374 // basic_parser::put(ConstBufferSequence const&,...) which avoids
1375 // buffer flattening.
1376 auto multibufs = [](multi_buffer::const_buffers_type buffers) {
1377 std::vector<net::const_buffer> bs;
1378 for (auto b : buffers_range(buffers))
1379 bs.push_back(b);
1380 while (std::distance(bs.begin(), bs.end()) < 2) {
1381 bs.push_back({});
1382 }
1383 return bs;
1384 };
1385
1386 // Buffers must be bigger than max_stack_buffer to force flattening
1387 // in basic_parser::put(ConstBufferSequence const&,...)
1388 std::string first_chunk_data(
1389 2 * basic_parser<false>::max_stack_buffer + 1, 'x');
1390
1391 std::string second_chunk_data_part1(
1392 basic_parser<false>::max_stack_buffer + 2, 'x');
1393 std::string second_chunk_data_part2(
1394 basic_parser<false>::max_stack_buffer + 1, 'x');
1395
1396 multi_buffer b;
1397 parser<false, string_body> p;
1398 p.eager(true);
1399 error_code ec;
1400 std::size_t used;
1401
1402 ostream(b) <<
1403 "HTTP/1.1 200 OK\r\n"
1404 "Server: test\r\n"
1405 "Transfer-Encoding: chunked\r\n"
1406 "\r\n";
1407
1408 used = p.put(b.data(), ec);
1409 b.consume(used);
1410
1411 BEAST_EXPECT(net::buffer_size(b.data()) == 0);
1412 BEAST_EXPECTS(!ec, ec.message());
1413 BEAST_EXPECT(!p.is_done());
1414 BEAST_EXPECT(p.is_header_done());
1415
1416 ostream(b) <<
1417 std::hex <<
1418 first_chunk_data.size() << "\r\n" <<
1419 first_chunk_data << "\r\n";
1420
1421 // First chunk
1422 used = p.put(multibufs(b.data()), ec);
1423 b.consume(used);
1424
1425 BEAST_EXPECTS(ec == error::need_more, ec.message());
1426 BEAST_EXPECT(!p.is_done());
1427

Callers

nothing calls this directly

Calls 11

eagerMethod · 0.80
messageMethod · 0.80
need_eofMethod · 0.80
beginMethod · 0.45
endMethod · 0.45
putMethod · 0.45
dataMethod · 0.45
consumeMethod · 0.45
is_doneMethod · 0.45
is_header_doneMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected