#include "test.hpp"
+#include <boost/asio/io_service.hpp>
+#include <boost/asio/strand.hpp>
+
namespace boost {
namespace beast {
namespace websocket {
});
auto const check =
- [&](std::string const& s)
+ [&](error e, std::string const& s)
{
stream<test::stream> ws{ioc_};
auto tr = connect(ws.next_layer());
}
catch(system_error const& se)
{
- BEAST_EXPECT(se.code() == error::handshake_failed);
+ BEAST_EXPECTS(se.code() == e, se.what());
}
};
- // wrong HTTP version
- check(
+ // bad HTTP version
+ check(error::bad_http_version,
"HTTP/1.0 101 Switching Protocols\r\n"
"Server: beast\r\n"
"Upgrade: WebSocket\r\n"
"Sec-WebSocket-Version: 13\r\n"
"\r\n"
);
- // wrong status
- check(
- "HTTP/1.1 200 OK\r\n"
+ // no Connection
+ check(error::no_connection,
+ "HTTP/1.1 101 Switching Protocols\r\n"
"Server: beast\r\n"
"Upgrade: WebSocket\r\n"
- "Connection: upgrade\r\n"
"Sec-WebSocket-Accept: s3pPLMBiTxaQ9kYGzzhZRbK+xOo=\r\n"
"Sec-WebSocket-Version: 13\r\n"
"\r\n"
);
- // missing upgrade token
- check(
+ // no Connection upgrade
+ check(error::no_connection_upgrade,
+ "HTTP/1.1 101 Switching Protocols\r\n"
+ "Server: beast\r\n"
+ "Upgrade: WebSocket\r\n"
+ "Connection: keep-alive\r\n"
+ "Sec-WebSocket-Accept: s3pPLMBiTxaQ9kYGzzhZRbK+xOo=\r\n"
+ "Sec-WebSocket-Version: 13\r\n"
+ "\r\n"
+ );
+ // no Upgrade
+ check(error::no_upgrade,
"HTTP/1.1 101 Switching Protocols\r\n"
"Server: beast\r\n"
- "Upgrade: HTTP/2\r\n"
"Connection: upgrade\r\n"
"Sec-WebSocket-Accept: s3pPLMBiTxaQ9kYGzzhZRbK+xOo=\r\n"
"Sec-WebSocket-Version: 13\r\n"
"\r\n"
);
- // missing connection token
- check(
+ // no Upgrade websocket
+ check(error::no_upgrade_websocket,
"HTTP/1.1 101 Switching Protocols\r\n"
"Server: beast\r\n"
- "Upgrade: WebSocket\r\n"
- "Connection: keep-alive\r\n"
+ "Upgrade: HTTP/2\r\n"
+ "Connection: upgrade\r\n"
"Sec-WebSocket-Accept: s3pPLMBiTxaQ9kYGzzhZRbK+xOo=\r\n"
"Sec-WebSocket-Version: 13\r\n"
"\r\n"
);
- // missing accept key
- check(
+ // no Sec-WebSocket-Accept
+ check(error::no_sec_accept,
"HTTP/1.1 101 Switching Protocols\r\n"
"Server: beast\r\n"
"Upgrade: WebSocket\r\n"
"Sec-WebSocket-Version: 13\r\n"
"\r\n"
);
- // wrong accept key
- check(
+ // bad Sec-WebSocket-Accept
+ check(error::bad_sec_accept,
"HTTP/1.1 101 Switching Protocols\r\n"
"Server: beast\r\n"
"Upgrade: WebSocket\r\n"
"Sec-WebSocket-Version: 13\r\n"
"\r\n"
);
+ // declined
+ check(error::upgrade_declined,
+ "HTTP/1.1 200 OK\r\n"
+ "Server: beast\r\n"
+ "Upgrade: WebSocket\r\n"
+ "Connection: upgrade\r\n"
+ "Sec-WebSocket-Accept: s3pPLMBiTxaQ9kYGzzhZRbK+xOo=\r\n"
+ "Sec-WebSocket-Version: 13\r\n"
+ "\r\n"
+ );
}
// Compression Extensions for WebSocket
"permessage-deflate");
}
+ void
+ testMoveOnly()
+ {
+ boost::asio::io_context ioc;
+ stream<test::stream> ws{ioc};
+ ws.async_handshake("", "", move_only_handler{});
+ }
+
+ struct copyable_handler
+ {
+ template<class... Args>
+ void
+ operator()(Args&&...) const
+ {
+ }
+ };
+
+ void
+ testAsioHandlerInvoke()
+ {
+ // make sure things compile, also can set a
+ // breakpoint in asio_handler_invoke to make sure
+ // it is instantiated.
+ boost::asio::io_context ioc;
+ boost::asio::io_service::strand s{ioc};
+ stream<test::stream> ws{ioc};
+ ws.async_handshake("localhost", "/", s.wrap(copyable_handler{}));
+ }
+
void
run() override
{
testExtRead();
testExtWrite();
testExtNegotiate();
+ testMoveOnly();
+ testAsioHandlerInvoke();
}
};