Add is_upgrade() free function:

fix #195

This function returns `true` when the passed HTTP Request
indicates a WebSocket Upgrade. It does not validate the
contents of the fields: it just trivially accepts requests
which can only be a WebSocket Upgrade message.

Callers who wish to manually read HTTP requests in their
server implementation can use this function to determine if
the request should be routed to an instance of websocket::stream.
This commit is contained in:
Vinnie Falco
2017-07-20 08:12:15 -07:00
parent fa1f4c7d56
commit 4b3a21efec
5 changed files with 105 additions and 1 deletions
+40
View File
@@ -7,3 +7,43 @@
// Test that header file is self-contained.
#include <beast/websocket/rfc6455.hpp>
#include <beast/unit_test/suite.hpp>
namespace beast {
namespace websocket {
class rfc6455_test
: public beast::unit_test::suite
{
public:
void
test_is_upgrade()
{
http::request_header req;
req.version = 10;
BEAST_EXPECT(! is_upgrade(req));
req.version = 11;
req.method = "POST";
req.url = "/";
BEAST_EXPECT(! is_upgrade(req));
req.method = "GET";
req.fields.insert("Connection", "upgrade");
BEAST_EXPECT(! is_upgrade(req));
req.fields.insert("Upgrade", "websocket");
BEAST_EXPECT(! is_upgrade(req));
req.fields.insert("Sec-WebSocket-Version", "13");
BEAST_EXPECT(is_upgrade(req));
}
void
run() override
{
test_is_upgrade();
}
};
BEAST_DEFINE_TESTSUITE(rfc6455,websocket,beast);
} // websocket
} // beast