permessage-deflate is a compile-time feature (API Change):

fix #849

This adds an additional `bool` template parameter to
`websocket::stream`:

* When deflateSupported is `true`, the stream will be capable
  of negotiating the permessage-deflate websocket extension per
  the configured run-time settings.

* When deflateSupported is `false`, the stream will never negotiate
  the permessage-deflate websocket extension. Furthermore, all of the
  code necessary for implementing the permessage-deflate extension
  will be excluded from function instantiations. The resulting emitted
  object code should be smaller.
This commit is contained in:
Vinnie Falco committed 2017-12-30 13:23:41 -08:00
1 parent 65d92f62fb
commit 841ab8474b
20 files changed
+1315 -721

No files matched your search

+60 -33
View File
@@ -23,11 +23,11 @@ namespace websocket {
class read1_test : public websocket_test_suite
{
public:
template<class Wrap>
template<class Wrap, bool deflateSupported>
void
doReadTest(
Wrap const& w,
ws_type& ws,
ws_type_t<deflateSupported>& ws,
close_code code)
{
try
@@ -45,11 +45,11 @@ public:
}
}
template<class Wrap>
template<class Wrap, bool deflateSupported>
void
doFailTest(
Wrap const& w,
ws_type& ws,
ws_type_t<deflateSupported>& ws,
error_code ev)
{
try
@@ -65,7 +65,7 @@ public:
}
}
template<class Wrap>
template<bool deflateSupported = true, class Wrap>
void
doTestRead(Wrap const& w)
{
@@ -78,7 +78,7 @@ public:
// already closed
{
echo_server es{log};
stream<test::stream> ws{ioc_};
stream<test::stream, deflateSupported> ws{ioc_};
ws.next_layer().connect(es.stream());
ws.handshake("localhost", "/");
ws.close({});
@@ -97,7 +97,8 @@ public:
}
// empty, fragmented message
doTest(pmd, [&](ws_type& ws)
doTest<deflateSupported>(pmd,
[&](ws_type_t<deflateSupported>& ws)
{
ws.next_layer().append(
string_view(
@@ -109,7 +110,8 @@ public:
// two part message
// triggers "fill the read buffer first"
doTest(pmd, [&](ws_type& ws)
doTest<deflateSupported>(pmd,
[&](ws_type_t<deflateSupported>& ws)
{
w.write_raw(ws, sbuf(
"\x01\x81\xff\xff\xff\xff"));
@@ -123,7 +125,8 @@ public:
});
// ping
doTest(pmd, [&](ws_type& ws)
doTest<deflateSupported>(pmd,
[&](ws_type_t<deflateSupported>& ws)
{
put(ws.next_layer().buffer(), cbuf(
0x89, 0x00));
@@ -144,7 +147,8 @@ public:
});
// ping
doTest(pmd, [&](ws_type& ws)
doTest<deflateSupported>(pmd,
[&](ws_type_t<deflateSupported>& ws)
{
put(ws.next_layer().buffer(), cbuf(
0x88, 0x00));
@@ -161,7 +165,8 @@ public:
});
// ping then message
doTest(pmd, [&](ws_type& ws)
doTest<deflateSupported>(pmd,
[&](ws_type_t<deflateSupported>& ws)
{
bool once = false;
ws.control_callback(
@@ -183,7 +188,8 @@ public:
});
// ping then fragmented message
doTest(pmd, [&](ws_type& ws)
doTest<deflateSupported>(pmd,
[&](ws_type_t<deflateSupported>& ws)
{
bool once = false;
ws.control_callback(
@@ -208,7 +214,7 @@ public:
doStreamLoop([&](test::stream& ts)
{
echo_server es{log, kind::async_client};
ws_type ws{ts};
ws_type_t<deflateSupported> ws{ts};
ws.next_layer().connect(es.stream());
ws.set_option(pmd);
es.async_handshake();
@@ -237,7 +243,7 @@ public:
{
echo_server es{log, kind::async};
boost::asio::io_context ioc;
stream<test::stream> ws{ioc, fc};
stream<test::stream, deflateSupported> ws{ioc, fc};
ws.next_layer().connect(es.stream());
ws.handshake("localhost", "/");
// Cause close to be received
@@ -257,7 +263,8 @@ public:
});
// already closed
doTest(pmd, [&](ws_type& ws)
doTest<deflateSupported>(pmd,
[&](ws_type_t<deflateSupported>& ws)
{
w.close(ws, {});
multi_buffer b;
@@ -266,7 +273,8 @@ public:
});
// buffer overflow
doTest(pmd, [&](ws_type& ws)
doTest<deflateSupported>(pmd,
[&](ws_type_t<deflateSupported>& ws)
{
std::string const s = "Hello, world!";
ws.auto_fragment(false);
@@ -286,7 +294,8 @@ public:
});
// bad utf8, big
doTest(pmd, [&](ws_type& ws)
doTest<deflateSupported>(pmd,
[&](ws_type_t<deflateSupported>& ws)
{
auto const s = std::string(2000, '*') +
random_string();
@@ -296,7 +305,8 @@ public:
});
// invalid fixed frame header
doTest(pmd, [&](ws_type& ws)
doTest<deflateSupported>(pmd,
[&](ws_type_t<deflateSupported>& ws)
{
w.write_raw(ws, cbuf(
0x8f, 0x80, 0xff, 0xff, 0xff, 0xff));
@@ -304,7 +314,8 @@ public:
});
// bad close
doTest(pmd, [&](ws_type& ws)
doTest<deflateSupported>(pmd,
[&](ws_type_t<deflateSupported>& ws)
{
put(ws.next_layer().buffer(), cbuf(
0x88, 0x02, 0x03, 0xed));
@@ -312,7 +323,8 @@ public:
});
// message size above 2^64
doTest(pmd, [&](ws_type& ws)
doTest<deflateSupported>(pmd,
[&](ws_type_t<deflateSupported>& ws)
{
w.write_some(ws, false, sbuf("*"));
w.write_raw(ws, cbuf(
@@ -322,7 +334,8 @@ public:
});
// message size exceeds max
doTest(pmd, [&](ws_type& ws)
doTest<deflateSupported>(pmd,
[&](ws_type_t<deflateSupported>& ws)
{
ws.read_message_max(1);
w.write(ws, sbuf("**"));
@@ -330,7 +343,8 @@ public:
});
// bad utf8
doTest(pmd, [&](ws_type& ws)
doTest<deflateSupported>(pmd,
[&](ws_type_t<deflateSupported>& ws)
{
put(ws.next_layer().buffer(), cbuf(
0x81, 0x06, 0x03, 0xea, 0xf0, 0x28, 0x8c, 0xbc));
@@ -338,7 +352,8 @@ public:
});
// incomplete utf8
doTest(pmd, [&](ws_type& ws)
doTest<deflateSupported>(pmd,
[&](ws_type_t<deflateSupported>& ws)
{
std::string const s =
"Hello, world!" "\xc0";
@@ -347,7 +362,8 @@ public:
});
// incomplete utf8, big
doTest(pmd, [&](ws_type& ws)
doTest<deflateSupported>(pmd,
[&](ws_type_t<deflateSupported>& ws)
{
std::string const s =
"\x81\x7e\x0f\xa1" +
@@ -375,7 +391,7 @@ public:
[&](error_code ev, string_view s)
{
echo_server es{log};
stream<test::stream> ws{ioc_};
stream<test::stream, deflateSupported> ws{ioc_};
ws.next_layer().connect(es.stream());
w.handshake(ws, "localhost", "/");
ws.next_layer().append(s);
@@ -410,11 +426,15 @@ public:
check(error::closed,
"\x88\x06\xfc\x15utf8");
}
}
//
// permessage-deflate
//
template<class Wrap>
void
doTestReadDeflate(Wrap const& w)
{
using boost::asio::buffer;
permessage_deflate pmd;
pmd.client_enable = true;
pmd.server_enable = true;
pmd.client_max_window_bits = 9;
@@ -422,7 +442,8 @@ public:
pmd.compLevel = 1;
// message size limit
doTest(pmd, [&](ws_type& ws)
doTest<true>(pmd,
[&](ws_type_t<true>& ws)
{
std::string const s = std::string(128, '*');
w.write(ws, buffer(s));
@@ -431,7 +452,8 @@ public:
});
// invalid inflate block
doTest(pmd, [&](ws_type& ws)
doTest<true>(pmd,
[&](ws_type_t<true>& ws)
{
auto const& s = random_string();
ws.binary(true);
@@ -458,7 +480,8 @@ public:
// no_context_takeover
pmd.server_no_context_takeover = true;
doTest(pmd, [&](ws_type& ws)
doTest<true>(pmd,
[&](ws_type_t<true>& ws)
{
auto const& s = random_string();
ws.binary(true);
@@ -587,10 +610,14 @@ public:
{
using boost::asio::buffer;
doTestRead(SyncClient{});
doTestRead<false>(SyncClient{});
doTestRead<true>(SyncClient{});
doTestReadDeflate(SyncClient{});
yield_to([&](yield_context yield)
{
doTestRead(AsyncClient{yield});
doTestRead<false>(AsyncClient{yield});
doTestRead<true>(AsyncClient{yield});
doTestReadDeflate(AsyncClient{yield});
});
permessage_deflate pmd;
+2
View File
@@ -122,6 +122,8 @@ public:
BOOST_STATIC_ASSERT(! std::is_move_assignable<
stream<test::stream&>>::value);
log << "sizeof(websocket::stream_base<true>) == " <<
sizeof(websocket::detail::stream_base<true>) << std::endl;
log << "sizeof(websocket::stream) == " <<
sizeof(websocket::stream<test::stream&>) << std::endl;
+182 -106
View File
@@ -35,6 +35,10 @@ class websocket_test_suite
, public test::enable_yield_to
{
public:
template<bool deflateSupported>
using ws_type_t =
websocket::stream<test::stream&, deflateSupported>;
using ws_type =
websocket::stream<test::stream&>;
@@ -303,7 +307,7 @@ public:
, limit);
}
template<class Test>
template<bool deflateSupported = true, class Test>
void
doTest(
permessage_deflate const& pmd,
@@ -320,7 +324,7 @@ public:
{
test::fail_counter fc{n};
test::stream ts{ioc_, fc};
ws_type ws{ts};
ws_type_t<deflateSupported> ws{ts};
ws.set_option(pmd);
echo_server es{log, i==1 ?
@@ -481,146 +485,171 @@ public:
struct SyncClient
{
template<class NextLayer>
template<class NextLayer, bool deflateSupported>
void
accept(stream<NextLayer>& ws) const
accept(
stream<NextLayer, deflateSupported>& ws) const
{
ws.accept();
}
template<class NextLayer, class Buffers>
template<
class NextLayer, bool deflateSupported,
class Buffers>
typename std::enable_if<
! http::detail::is_header<Buffers>::value>::type
accept(stream<NextLayer>& ws,
accept(stream<NextLayer, deflateSupported>& ws,
Buffers const& buffers) const
{
ws.accept(buffers);
}
template<class NextLayer>
template<class NextLayer, bool deflateSupported>
void
accept(stream<NextLayer>& ws,
accept(
stream<NextLayer, deflateSupported>& ws,
http::request<http::empty_body> const& req) const
{
ws.accept(req);
}
template<class NextLayer, class Decorator>
template<
class NextLayer, bool deflateSupported,
class Decorator>
void
accept_ex(stream<NextLayer>& ws,
accept_ex(
stream<NextLayer, deflateSupported>& ws,
Decorator const& d) const
{
ws.accept_ex(d);
}
template<class NextLayer,
template<
class NextLayer, bool deflateSupported,
class Buffers, class Decorator>
typename std::enable_if<
! http::detail::is_header<Buffers>::value>::type
accept_ex(stream<NextLayer>& ws,
accept_ex(
stream<NextLayer, deflateSupported>& ws,
Buffers const& buffers,
Decorator const& d) const
Decorator const& d) const
{
ws.accept_ex(buffers, d);
}
template<class NextLayer, class Decorator>
template<
class NextLayer, bool deflateSupported,
class Decorator>
void
accept_ex(stream<NextLayer>& ws,
accept_ex(
stream<NextLayer, deflateSupported>& ws,
http::request<http::empty_body> const& req,
Decorator const& d) const
Decorator const& d) const
{
ws.accept_ex(req, d);
}
template<class NextLayer,
template<
class NextLayer, bool deflateSupported,
class Buffers, class Decorator>
void
accept_ex(stream<NextLayer>& ws,
accept_ex(
stream<NextLayer, deflateSupported>& ws,
http::request<http::empty_body> const& req,
Buffers const& buffers,
Decorator const& d) const
Buffers const& buffers,
Decorator const& d) const
{
ws.accept_ex(req, buffers, d);
}
template<class NextLayer>
template<class NextLayer, bool deflateSupported>
void
handshake(stream<NextLayer>& ws,
handshake(
stream<NextLayer, deflateSupported>& ws,
string_view uri,
string_view path) const
string_view path) const
{
ws.handshake(uri, path);
}
template<class NextLayer>
template<class NextLayer, bool deflateSupported>
void
handshake(stream<NextLayer>& ws,
handshake(
stream<NextLayer, deflateSupported>& ws,
response_type& res,
string_view uri,
string_view path) const
string_view uri,
string_view path) const
{
ws.handshake(res, uri, path);
}
template<class NextLayer, class Decorator>
template<
class NextLayer, bool deflateSupported,
class Decorator>
void
handshake_ex(stream<NextLayer>& ws,
handshake_ex(
stream<NextLayer, deflateSupported>& ws,
string_view uri,
string_view path,
Decorator const& d) const
string_view path,
Decorator const& d) const
{
ws.handshake_ex(uri, path, d);
}
template<class NextLayer, class Decorator>
template<
class NextLayer, bool deflateSupported,
class Decorator>
void
handshake_ex(stream<NextLayer>& ws,
handshake_ex(
stream<NextLayer, deflateSupported>& ws,
response_type& res,
string_view uri,
string_view path,
Decorator const& d) const
string_view uri,
string_view path,
Decorator const& d) const
{
ws.handshake_ex(res, uri, path, d);
}
template<class NextLayer>
template<class NextLayer, bool deflateSupported>
void
ping(stream<NextLayer>& ws,
ping(stream<NextLayer, deflateSupported>& ws,
ping_data const& payload) const
{
ws.ping(payload);
}
template<class NextLayer>
template<class NextLayer, bool deflateSupported>
void
pong(stream<NextLayer>& ws,
pong(stream<NextLayer, deflateSupported>& ws,
ping_data const& payload) const
{
ws.pong(payload);
}
template<class NextLayer>
template<class NextLayer, bool deflateSupported>
void
close(stream<NextLayer>& ws,
close(stream<NextLayer, deflateSupported>& ws,
close_reason const& cr) const
{
ws.close(cr);
}
template<
class NextLayer, class DynamicBuffer>
class NextLayer, bool deflateSupported,
class DynamicBuffer>
std::size_t
read(stream<NextLayer>& ws,
read(stream<NextLayer, deflateSupported>& ws,
DynamicBuffer& buffer) const
{
return ws.read(buffer);
}
template<
class NextLayer, class DynamicBuffer>
class NextLayer, bool deflateSupported,
class DynamicBuffer>
std::size_t
read_some(stream<NextLayer>& ws,
read_some(
stream<NextLayer, deflateSupported>& ws,
std::size_t limit,
DynamicBuffer& buffer) const
{
@@ -628,36 +657,45 @@ public:
}
template<
class NextLayer, class MutableBufferSequence>
class NextLayer, bool deflateSupported,
class MutableBufferSequence>
std::size_t
read_some(stream<NextLayer>& ws,
read_some(
stream<NextLayer, deflateSupported>& ws,
MutableBufferSequence const& buffers) const
{
return ws.read_some(buffers);
}
template<
class NextLayer, class ConstBufferSequence>
class NextLayer, bool deflateSupported,
class ConstBufferSequence>
std::size_t
write(stream<NextLayer>& ws,
write(
stream<NextLayer, deflateSupported>& ws,
ConstBufferSequence const& buffers) const
{
return ws.write(buffers);
}
template<
class NextLayer, class ConstBufferSequence>
class NextLayer, bool deflateSupported,
class ConstBufferSequence>
std::size_t
write_some(stream<NextLayer>& ws, bool fin,
write_some(
stream<NextLayer, deflateSupported>& ws,
bool fin,
ConstBufferSequence const& buffers) const
{
return ws.write_some(fin, buffers);
}
template<
class NextLayer, class ConstBufferSequence>
class NextLayer, bool deflateSupported,
class ConstBufferSequence>
std::size_t
write_raw(stream<NextLayer>& ws,
write_raw(
stream<NextLayer, deflateSupported>& ws,
ConstBufferSequence const& buffers) const
{
return boost::asio::write(
@@ -678,9 +716,9 @@ public:
{
}
template<class NextLayer>
template<class NextLayer, bool deflateSupported>
void
accept(stream<NextLayer>& ws) const
accept(stream<NextLayer, deflateSupported>& ws) const
{
error_code ec;
ws.async_accept(yield_[ec]);
@@ -688,10 +726,13 @@ public:
throw system_error{ec};
}
template<class NextLayer, class Buffers>
template<
class NextLayer, bool deflateSupported,
class Buffers>
typename std::enable_if<
! http::detail::is_header<Buffers>::value>::type
accept(stream<NextLayer>& ws,
accept(
stream<NextLayer, deflateSupported>& ws,
Buffers const& buffers) const
{
error_code ec;
@@ -700,9 +741,10 @@ public:
throw system_error{ec};
}
template<class NextLayer>
template<class NextLayer, bool deflateSupported>
void
accept(stream<NextLayer>& ws,
accept(
stream<NextLayer, deflateSupported>& ws,
http::request<http::empty_body> const& req) const
{
error_code ec;
@@ -711,10 +753,12 @@ public:
throw system_error{ec};
}
template<class NextLayer,
template<
class NextLayer, bool deflateSupported,
class Decorator>
void
accept_ex(stream<NextLayer>& ws,
accept_ex(
stream<NextLayer, deflateSupported>& ws,
Decorator const& d) const
{
error_code ec;
@@ -723,13 +767,15 @@ public:
throw system_error{ec};
}
template<class NextLayer,
template<
class NextLayer, bool deflateSupported,
class Buffers, class Decorator>
typename std::enable_if<
! http::detail::is_header<Buffers>::value>::type
accept_ex(stream<NextLayer>& ws,
accept_ex(
stream<NextLayer, deflateSupported>& ws,
Buffers const& buffers,
Decorator const& d) const
Decorator const& d) const
{
error_code ec;
ws.async_accept_ex(buffers, d, yield_[ec]);
@@ -737,11 +783,14 @@ public:
throw system_error{ec};
}
template<class NextLayer, class Decorator>
template<
class NextLayer, bool deflateSupported,
class Decorator>
void
accept_ex(stream<NextLayer>& ws,
accept_ex(
stream<NextLayer, deflateSupported>& ws,
http::request<http::empty_body> const& req,
Decorator const& d) const
Decorator const& d) const
{
error_code ec;
ws.async_accept_ex(req, d, yield_[ec]);
@@ -749,13 +798,15 @@ public:
throw system_error{ec};
}
template<class NextLayer,
template<
class NextLayer, bool deflateSupported,
class Buffers, class Decorator>
void
accept_ex(stream<NextLayer>& ws,
accept_ex(
stream<NextLayer, deflateSupported>& ws,
http::request<http::empty_body> const& req,
Buffers const& buffers,
Decorator const& d) const
Buffers const& buffers,
Decorator const& d) const
{
error_code ec;
ws.async_accept_ex(
@@ -764,11 +815,13 @@ public:
throw system_error{ec};
}
template<class NextLayer>
template<
class NextLayer, bool deflateSupported>
void
handshake(stream<NextLayer>& ws,
handshake(
stream<NextLayer, deflateSupported>& ws,
string_view uri,
string_view path) const
string_view path) const
{
error_code ec;
ws.async_handshake(
@@ -777,12 +830,13 @@ public:
throw system_error{ec};
}
template<class NextLayer>
template<class NextLayer, bool deflateSupported>
void
handshake(stream<NextLayer>& ws,
handshake(
stream<NextLayer, deflateSupported>& ws,
response_type& res,
string_view uri,
string_view path) const
string_view uri,
string_view path) const
{
error_code ec;
ws.async_handshake(
@@ -791,12 +845,15 @@ public:
throw system_error{ec};
}
template<class NextLayer, class Decorator>
template<
class NextLayer, bool deflateSupported,
class Decorator>
void
handshake_ex(stream<NextLayer>& ws,
handshake_ex(
stream<NextLayer, deflateSupported>& ws,
string_view uri,
string_view path,
Decorator const &d) const
string_view path,
Decorator const &d) const
{
error_code ec;
ws.async_handshake_ex(
@@ -805,13 +862,16 @@ public:
throw system_error{ec};
}
template<class NextLayer, class Decorator>
template<
class NextLayer, bool deflateSupported,
class Decorator>
void
handshake_ex(stream<NextLayer>& ws,
handshake_ex(
stream<NextLayer, deflateSupported>& ws,
response_type& res,
string_view uri,
string_view path,
Decorator const &d) const
string_view uri,
string_view path,
Decorator const &d) const
{
error_code ec;
ws.async_handshake_ex(
@@ -820,9 +880,10 @@ public:
throw system_error{ec};
}
template<class NextLayer>
template<class NextLayer, bool deflateSupported>
void
ping(stream<NextLayer>& ws,
ping(
stream<NextLayer, deflateSupported>& ws,
ping_data const& payload) const
{
error_code ec;
@@ -831,9 +892,10 @@ public:
throw system_error{ec};
}
template<class NextLayer>
template<class NextLayer, bool deflateSupported>
void
pong(stream<NextLayer>& ws,
pong(
stream<NextLayer, deflateSupported>& ws,
ping_data const& payload) const
{
error_code ec;
@@ -842,9 +904,10 @@ public:
throw system_error{ec};
}
template<class NextLayer>
template<class NextLayer, bool deflateSupported>
void
close(stream<NextLayer>& ws,
close(
stream<NextLayer, deflateSupported>& ws,
close_reason const& cr) const
{
error_code ec;
@@ -854,9 +917,11 @@ public:
}
template<
class NextLayer, class DynamicBuffer>
class NextLayer, bool deflateSupported,
class DynamicBuffer>
std::size_t
read(stream<NextLayer>& ws,
read(
stream<NextLayer, deflateSupported>& ws,
DynamicBuffer& buffer) const
{
error_code ec;
@@ -868,9 +933,11 @@ public:
}
template<
class NextLayer, class DynamicBuffer>
class NextLayer, bool deflateSupported,
class DynamicBuffer>
std::size_t
read_some(stream<NextLayer>& ws,
read_some(
stream<NextLayer, deflateSupported>& ws,
std::size_t limit,
DynamicBuffer& buffer) const
{
@@ -883,9 +950,11 @@ public:
}
template<
class NextLayer, class MutableBufferSequence>
class NextLayer, bool deflateSupported,
class MutableBufferSequence>
std::size_t
read_some(stream<NextLayer>& ws,
read_some(
stream<NextLayer, deflateSupported>& ws,
MutableBufferSequence const& buffers) const
{
error_code ec;
@@ -897,9 +966,11 @@ public:
}
template<
class NextLayer, class ConstBufferSequence>
class NextLayer, bool deflateSupported,
class ConstBufferSequence>
std::size_t
write(stream<NextLayer>& ws,
write(
stream<NextLayer, deflateSupported>& ws,
ConstBufferSequence const& buffers) const
{
error_code ec;
@@ -911,9 +982,12 @@ public:
}
template<
class NextLayer, class ConstBufferSequence>
class NextLayer, bool deflateSupported,
class ConstBufferSequence>
std::size_t
write_some(stream<NextLayer>& ws, bool fin,
write_some(
stream<NextLayer, deflateSupported>& ws,
bool fin,
ConstBufferSequence const& buffers) const
{
error_code ec;
@@ -925,9 +999,11 @@ public:
}
template<
class NextLayer, class ConstBufferSequence>
class NextLayer, bool deflateSupported,
class ConstBufferSequence>
std::size_t
write_raw(stream<NextLayer>& ws,
write_raw(
stream<NextLayer, deflateSupported>& ws,
ConstBufferSequence const& buffers) const
{
error_code ec;
+31 -12
View File
@@ -19,7 +19,7 @@ namespace websocket {
class write_test : public websocket_test_suite
{
public:
template<class Wrap>
template<bool deflateSupported, class Wrap>
void
doTestWrite(Wrap const& w)
{
@@ -50,7 +50,8 @@ public:
}
// message
doTest(pmd, [&](ws_type& ws)
doTest<deflateSupported>(pmd,
[&](ws_type_t<deflateSupported>& ws)
{
ws.auto_fragment(false);
ws.binary(false);
@@ -63,7 +64,8 @@ public:
});
// empty message
doTest(pmd, [&](ws_type& ws)
doTest<deflateSupported>(pmd,
[&](ws_type_t<deflateSupported>& ws)
{
ws.text(true);
w.write(ws, boost::asio::const_buffer{});
@@ -74,7 +76,8 @@ public:
});
// fragmented message
doTest(pmd, [&](ws_type& ws)
doTest<deflateSupported>(pmd,
[&](ws_type_t<deflateSupported>& ws)
{
ws.auto_fragment(false);
ws.binary(false);
@@ -88,7 +91,8 @@ public:
});
// continuation
doTest(pmd, [&](ws_type& ws)
doTest<deflateSupported>(pmd,
[&](ws_type_t<deflateSupported>& ws)
{
std::string const s = "Hello";
std::size_t const chop = 3;
@@ -103,7 +107,8 @@ public:
});
// mask
doTest(pmd, [&](ws_type& ws)
doTest<deflateSupported>(pmd,
[&](ws_type_t<deflateSupported>& ws)
{
ws.auto_fragment(false);
std::string const s = "Hello";
@@ -114,7 +119,8 @@ public:
});
// mask (large)
doTest(pmd, [&](ws_type& ws)
doTest<deflateSupported>(pmd,
[&](ws_type_t<deflateSupported>& ws)
{
ws.auto_fragment(false);
ws.write_buffer_size(16);
@@ -126,7 +132,8 @@ public:
});
// mask, autofrag
doTest(pmd, [&](ws_type& ws)
doTest<deflateSupported>(pmd,
[&](ws_type_t<deflateSupported>& ws)
{
ws.auto_fragment(true);
std::string const s(16384, '*');
@@ -140,7 +147,7 @@ public:
doStreamLoop([&](test::stream& ts)
{
echo_server es{log, kind::async_client};
ws_type ws{ts};
ws_type_t<deflateSupported> ws{ts};
ws.next_layer().connect(es.stream());
try
{
@@ -166,7 +173,7 @@ public:
doStreamLoop([&](test::stream& ts)
{
echo_server es{log, kind::async_client};
ws_type ws{ts};
ws_type_t<deflateSupported> ws{ts};
ws.next_layer().connect(es.stream());
try
{
@@ -187,7 +194,15 @@ public:
}
ts.close();
});
}
template<class Wrap>
void
doTestWriteDeflate(Wrap const& w)
{
using boost::asio::buffer;
permessage_deflate pmd;
pmd.client_enable = true;
pmd.server_enable = true;
pmd.compLevel = 1;
@@ -238,11 +253,15 @@ public:
{
using boost::asio::buffer;
doTestWrite(SyncClient{});
doTestWrite<false>(SyncClient{});
doTestWrite<true>(SyncClient{});
doTestWriteDeflate(SyncClient{});
yield_to([&](yield_context yield)
{
doTestWrite(AsyncClient{yield});
doTestWrite<false>(AsyncClient{yield});
doTestWrite<true>(AsyncClient{yield});
doTestWriteDeflate(AsyncClient{yield});
});
}
+11 -1
View File
@@ -57,7 +57,7 @@ boost::asio::ip::tcp::socket sock{ioc};
{
//[ws_snippet_6
std::string const host = "mywebapp.com";
std::string const host = "example.com";
boost::asio::ip::tcp::resolver r{ioc};
stream<boost::asio::ip::tcp::socket> ws{ioc};
auto const results = r.resolve(host, "ws");
@@ -310,6 +310,16 @@ struct custom_wrapper
//]
//[ws_snippet_26
// A WebSocket stream
template<
class NextLayer,
bool deflateSupported = true>
class stream;
//]
} // doc_ws_snippets
//------------------------------------------------------------------------------