per-message compression options

fix #226, #227
This commit is contained in:
alandefreitas
2022-10-03 09:25:31 +08:00
committed by Klemens
parent 677a3e0179
commit bd69638e9d
9 changed files with 178 additions and 14 deletions
+89
View File
@@ -651,6 +651,92 @@ public:
}
}
/*
https://github.com/boostorg/beast/issues/227
intelligent compression.
*/
void
testIssue226()
{
net::io_context ioc;
permessage_deflate pmd;
pmd.client_enable = true;
pmd.server_enable = true;
pmd.msg_size_threshold = 5;
stream<test::stream> ws0{ioc};
stream<test::stream> ws1{ioc};
ws0.next_layer().connect(ws1.next_layer());
ws0.set_option(pmd);
ws1.set_option(pmd);
ws1.async_accept(
[](error_code ec)
{
BEAST_EXPECTS(! ec, ec.message());
});
ws0.async_handshake("test", "/",
[](error_code ec)
{
BEAST_EXPECTS(! ec, ec.message());
});
ioc.run();
ioc.restart();
std::string s(256, '*');
auto const n0 =
ws0.next_layer().nwrite_bytes();
error_code ec;
BEAST_EXPECTS(! ec, ec.message());
ws1.compress(false);
ws1.write(net::buffer(s), ec);
ws1.compress(true);
auto const n1 =
ws0.next_layer().nwrite_bytes();
// Make sure the string was actually compressed
BEAST_EXPECT(n1 > n0 + s.size());
}
/*
https://github.com/boostorg/beast/issues/227
intelligent compression.
*/
void
testIssue227()
{
net::io_context ioc;
permessage_deflate pmd;
pmd.client_enable = true;
pmd.server_enable = true;
pmd.msg_size_threshold = 260;
stream<test::stream> ws0{ioc};
stream<test::stream> ws1{ioc};
ws0.next_layer().connect(ws1.next_layer());
ws0.set_option(pmd);
ws1.set_option(pmd);
ws1.async_accept(
[](error_code ec)
{
BEAST_EXPECTS(! ec, ec.message());
});
ws0.async_handshake("test", "/",
[](error_code ec)
{
BEAST_EXPECTS(! ec, ec.message());
});
ioc.run();
ioc.restart();
std::string s(256, '*');
auto const n0 =
ws0.next_layer().nwrite_bytes();
error_code ec;
BEAST_EXPECTS(! ec, ec.message());
ws1.write(net::buffer(s), ec);
auto const n1 =
ws0.next_layer().nwrite_bytes();
// Make sure the string was actually compressed
BEAST_EXPECT(n1 > n0 + s.size());
}
/*
https://github.com/boostorg/beast/issues/300
@@ -720,6 +806,7 @@ public:
BEAST_EXPECT(n1 < n0 + s.size());
}
#if BOOST_ASIO_HAS_CO_AWAIT
void testAwaitableCompiles(
stream<test::stream>& s,
@@ -744,6 +831,8 @@ public:
testWriteSuspend();
testAsyncWriteFrame();
testMoveOnly();
testIssue226();
testIssue227();
testIssue300();
testIssue1666();
#if BOOST_ASIO_HAS_CO_AWAIT