forked from boostorg/beast
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:
1 parent
fa1f4c7d56
commit
4b3a21efec
5 files changed
+105
-1
No files matched your search
@@ -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
|
||||
Reference in new issue
Block a user