mirror of
https://github.com/CrowCpp/Crow.git
synced 2024-06-07 21:10:44 +00:00
Make stream_response test independent of header size
The test was failing when built using my mingw64-11.2.0 toolset on the Windows platform, on the 1.0+3 release.
This commit is contained in:
parent
1d208aea39
commit
f7758feab5
@ -2240,7 +2240,7 @@ TEST_CASE("stream_response")
|
||||
app.validate();
|
||||
|
||||
// running the test on a separate thread to allow the client to sleep
|
||||
std::thread runTest([&app, &key_response, key_response_size]() {
|
||||
std::thread runTest([&app, &key_response, key_response_size, keyword_]() {
|
||||
auto _ = app.bindaddr(LOCALHOST_ADDRESS).port(45451).run_async();
|
||||
app.wait_for_server_start();
|
||||
asio::io_service is;
|
||||
@ -2257,15 +2257,21 @@ TEST_CASE("stream_response")
|
||||
asio::ip::address::from_string(LOCALHOST_ADDRESS), 45451));
|
||||
c.send(asio::buffer(sendmsg));
|
||||
|
||||
//consuming the headers, since we don't need those for the test
|
||||
// consuming the headers, since we don't need those for the test
|
||||
static char buf[2048];
|
||||
size_t received_headers_bytes = 0;
|
||||
|
||||
// magic number is 102 (it's the size of the headers, which is how much this line below needs to read)
|
||||
const size_t headers_bytes = 102;
|
||||
while (received_headers_bytes < headers_bytes)
|
||||
received_headers_bytes += c.receive(asio::buffer(buf, 102));
|
||||
received += received_headers_bytes - headers_bytes; //add any extra that might have been received to the proper received count
|
||||
// Magic number is 102. It's the size of the headers, which is at
|
||||
// least how much we need to read. Since the header size may change
|
||||
// and break the test, we read twice as much as the header and
|
||||
// search in the received data for the first occurrence of keyword_.
|
||||
const size_t headers_bytes_and_some = 102 * 2;
|
||||
while (received_headers_bytes < headers_bytes_and_some)
|
||||
received_headers_bytes += c.receive(asio::buffer(buf + received_headers_bytes,
|
||||
sizeof(buf) / sizeof(buf[0]) - received_headers_bytes));
|
||||
|
||||
const std::string::size_type header_end_pos = std::string(buf, received_headers_bytes).find(keyword_);
|
||||
received += received_headers_bytes - header_end_pos; // add any extra that might have been received to the proper received count
|
||||
|
||||
while (received < key_response_size)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user