2016-05-07 15:18:22 -04:00
|
|
|
//
|
|
|
|
|
// Copyright (c) 2013-2016 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)
|
|
|
|
|
//
|
2016-05-01 11:14:10 -04:00
|
|
|
|
|
|
|
|
// Test that header file is self-contained.
|
|
|
|
|
#include <beast/http/message_v1.hpp>
|
|
|
|
|
|
2016-05-06 19:14:17 -04:00
|
|
|
#include <beast/unit_test/suite.hpp>
|
2016-04-30 10:29:39 -04:00
|
|
|
#include <beast/http/empty_body.hpp>
|
2016-05-01 11:14:10 -04:00
|
|
|
|
|
|
|
|
namespace beast {
|
|
|
|
|
namespace http {
|
|
|
|
|
|
2016-05-07 15:18:22 -04:00
|
|
|
class message_v1_test : public beast::unit_test::suite
|
2016-05-01 11:14:10 -04:00
|
|
|
{
|
|
|
|
|
public:
|
2016-04-30 10:29:39 -04:00
|
|
|
void testFreeFunctions()
|
|
|
|
|
{
|
|
|
|
|
{
|
|
|
|
|
request_v1<empty_body> m;
|
|
|
|
|
m.method = "GET";
|
|
|
|
|
m.url = "/";
|
|
|
|
|
m.version = 11;
|
|
|
|
|
m.headers.insert("Upgrade", "test");
|
|
|
|
|
expect(! is_upgrade(m));
|
2016-05-01 11:14:10 -04:00
|
|
|
|
2016-04-30 10:29:39 -04:00
|
|
|
prepare(m, connection::upgrade);
|
|
|
|
|
expect(is_upgrade(m));
|
|
|
|
|
expect(m.headers["Connection"] == "upgrade");
|
|
|
|
|
|
|
|
|
|
m.version = 10;
|
|
|
|
|
expect(! is_upgrade(m));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void testPrepare()
|
2016-05-04 17:27:50 -04:00
|
|
|
{
|
|
|
|
|
request_v1<empty_body> m;
|
|
|
|
|
m.version = 10;
|
|
|
|
|
expect(! is_upgrade(m));
|
|
|
|
|
m.headers.insert("Transfer-Encoding", "chunked");
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
prepare(m);
|
|
|
|
|
fail();
|
|
|
|
|
}
|
|
|
|
|
catch(std::exception const&)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
m.headers.erase("Transfer-Encoding");
|
|
|
|
|
m.headers.insert("Content-Length", "0");
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
prepare(m);
|
|
|
|
|
fail();
|
|
|
|
|
}
|
|
|
|
|
catch(std::exception const&)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
m.headers.erase("Content-Length");
|
|
|
|
|
m.headers.insert("Connection", "keep-alive");
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
prepare(m);
|
|
|
|
|
fail();
|
|
|
|
|
}
|
|
|
|
|
catch(std::exception const&)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-05-01 11:14:10 -04:00
|
|
|
void run() override
|
|
|
|
|
{
|
2016-04-30 10:29:39 -04:00
|
|
|
testFreeFunctions();
|
|
|
|
|
testPrepare();
|
2016-05-01 11:14:10 -04:00
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2016-05-07 15:18:22 -04:00
|
|
|
BEAST_DEFINE_TESTSUITE(message_v1,http,beast);
|
2016-05-01 11:14:10 -04:00
|
|
|
|
|
|
|
|
} // http
|
|
|
|
|
} // beast
|