forked from boostorg/beast
Refactor WebSocket errors (API Change):
fix #949 * New error codes are introduced for WebSocket failures * More verbose messages for error codes * Error codes are mapped to conditions for ease of testing * error::failed and error::handshake_failed are deprecated (don't use) Actions Required: * Code which explicitly compares error_code values against the constant `websocket::error::handshake_failed` should compare against `websocket::condition::handshake_failed` instead. * Code which explicitly compares error_code values against the constant `websocket::error::failed` should compare against `websocket::condition::protocol_violation` instead.
This commit is contained in:
1 parent
08a9ed4c25
commit
cc43b46c42
19 files changed
+705
-346
No files matched your search
@@ -137,7 +137,7 @@ public:
|
||||
});
|
||||
|
||||
auto const check =
|
||||
[&](std::string const& s)
|
||||
[&](error e, std::string const& s)
|
||||
{
|
||||
stream<test::stream> ws{ioc_};
|
||||
auto tr = connect(ws.next_layer());
|
||||
@@ -150,11 +150,11 @@ public:
|
||||
}
|
||||
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"
|
||||
@@ -163,28 +163,17 @@ public:
|
||||
"Sec-WebSocket-Version: 13\r\n"
|
||||
"\r\n"
|
||||
);
|
||||
// wrong status
|
||||
check(
|
||||
"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"
|
||||
);
|
||||
// missing upgrade token
|
||||
check(
|
||||
// no Connection
|
||||
check(error::no_connection,
|
||||
"HTTP/1.1 101 Switching Protocols\r\n"
|
||||
"Server: beast\r\n"
|
||||
"Upgrade: HTTP/2\r\n"
|
||||
"Connection: upgrade\r\n"
|
||||
"Upgrade: WebSocket\r\n"
|
||||
"Sec-WebSocket-Accept: s3pPLMBiTxaQ9kYGzzhZRbK+xOo=\r\n"
|
||||
"Sec-WebSocket-Version: 13\r\n"
|
||||
"\r\n"
|
||||
);
|
||||
// missing connection 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"
|
||||
@@ -193,8 +182,27 @@ public:
|
||||
"Sec-WebSocket-Version: 13\r\n"
|
||||
"\r\n"
|
||||
);
|
||||
// missing accept key
|
||||
check(
|
||||
// no Upgrade
|
||||
check(error::no_upgrade,
|
||||
"HTTP/1.1 101 Switching Protocols\r\n"
|
||||
"Server: beast\r\n"
|
||||
"Connection: upgrade\r\n"
|
||||
"Sec-WebSocket-Accept: s3pPLMBiTxaQ9kYGzzhZRbK+xOo=\r\n"
|
||||
"Sec-WebSocket-Version: 13\r\n"
|
||||
"\r\n"
|
||||
);
|
||||
// no Upgrade websocket
|
||||
check(error::no_upgrade_websocket,
|
||||
"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"
|
||||
);
|
||||
// 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"
|
||||
@@ -202,8 +210,8 @@ public:
|
||||
"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"
|
||||
@@ -212,6 +220,16 @@ public:
|
||||
"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
|
||||
|
||||
Reference in new issue
Block a user