forked from boostorg/beast
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.
50 lines
1.2 KiB
C++
50 lines
1.2 KiB
C++
//
|
|
// Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com)
|
|
//
|
|
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
|
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
|
//
|
|
|
|
// 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
|