2016-05-07 15:18:22 -04:00
|
|
|
//
|
2019-02-21 07:00:31 -08:00
|
|
|
// Copyright (c) 2016-2019 Vinnie Falco (vinnie dot falco at gmail dot com)
|
2016-05-07 15:18:22 -04:00
|
|
|
//
|
|
|
|
|
// 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)
|
|
|
|
|
//
|
2017-07-20 13:40:34 -07:00
|
|
|
// Official repository: https://github.com/boostorg/beast
|
|
|
|
|
//
|
2017-07-20 08:01:46 -07:00
|
|
|
|
|
|
|
|
// Test that header file is self-contained.
|
2017-07-20 13:40:34 -07:00
|
|
|
#include <boost/beast/http/message.hpp>
|
2016-05-07 15:18:22 -04:00
|
|
|
|
2017-07-20 13:40:34 -07:00
|
|
|
#include <boost/beast/http/empty_body.hpp>
|
|
|
|
|
#include <boost/beast/http/string_body.hpp>
|
|
|
|
|
#include <boost/beast/http/fields.hpp>
|
|
|
|
|
#include <boost/beast/http/string_body.hpp>
|
2018-11-11 14:07:55 -08:00
|
|
|
#include <boost/beast/_experimental/unit_test/suite.hpp>
|
2016-05-07 15:18:22 -04:00
|
|
|
#include <type_traits>
|
|
|
|
|
|
2017-07-20 13:40:34 -07:00
|
|
|
namespace boost {
|
2016-05-07 15:18:22 -04:00
|
|
|
namespace beast {
|
|
|
|
|
namespace http {
|
|
|
|
|
|
|
|
|
|
class message_test : public beast::unit_test::suite
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
struct Arg1
|
|
|
|
|
{
|
|
|
|
|
bool moved = false;
|
|
|
|
|
|
2017-08-08 07:17:24 -07:00
|
|
|
Arg1(Arg1 const&) = default;
|
|
|
|
|
|
|
|
|
|
Arg1()
|
|
|
|
|
{
|
|
|
|
|
}
|
2016-05-07 15:18:22 -04:00
|
|
|
|
|
|
|
|
Arg1(Arg1&& other)
|
|
|
|
|
{
|
|
|
|
|
other.moved = true;
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct Arg2 { };
|
|
|
|
|
struct Arg3 { };
|
|
|
|
|
|
|
|
|
|
// default constructible Body
|
|
|
|
|
struct default_body
|
|
|
|
|
{
|
|
|
|
|
using value_type = std::string;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// 1-arg constructible Body
|
|
|
|
|
struct one_arg_body
|
|
|
|
|
{
|
|
|
|
|
struct value_type
|
|
|
|
|
{
|
|
|
|
|
explicit
|
|
|
|
|
value_type(Arg1 const&)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
explicit
|
|
|
|
|
value_type(Arg1&& arg)
|
|
|
|
|
{
|
|
|
|
|
Arg1 arg_(std::move(arg));
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// 2-arg constructible Body
|
|
|
|
|
struct two_arg_body
|
|
|
|
|
{
|
|
|
|
|
struct value_type
|
|
|
|
|
{
|
|
|
|
|
value_type(Arg1 const&, Arg2 const&)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
|
2017-07-03 20:33:54 -07:00
|
|
|
// 0-arg
|
|
|
|
|
BOOST_STATIC_ASSERT(std::is_constructible<
|
|
|
|
|
request<default_body>>::value);
|
|
|
|
|
|
|
|
|
|
// 1-arg
|
|
|
|
|
BOOST_STATIC_ASSERT(! std::is_constructible<request<one_arg_body>
|
|
|
|
|
>::value);
|
2016-05-10 21:21:19 -04:00
|
|
|
|
2017-07-03 20:33:54 -07:00
|
|
|
//BOOST_STATIC_ASSERT(! std::is_constructible<request<one_arg_body>,
|
|
|
|
|
// verb, string_view, unsigned>::value);
|
2016-05-10 21:21:19 -04:00
|
|
|
|
2017-07-03 20:33:54 -07:00
|
|
|
BOOST_STATIC_ASSERT(std::is_constructible<request<one_arg_body>,
|
|
|
|
|
verb, string_view, unsigned, Arg1>::value);
|
2016-05-10 21:21:19 -04:00
|
|
|
|
2017-07-03 20:33:54 -07:00
|
|
|
BOOST_STATIC_ASSERT(std::is_constructible<request<one_arg_body>,
|
|
|
|
|
verb, string_view, unsigned, Arg1&&>::value);
|
2016-05-10 21:21:19 -04:00
|
|
|
|
2017-07-03 20:33:54 -07:00
|
|
|
BOOST_STATIC_ASSERT(std::is_constructible<request<one_arg_body>,
|
|
|
|
|
verb, string_view, unsigned, Arg1 const>::value);
|
2016-05-10 21:21:19 -04:00
|
|
|
|
2017-07-03 20:33:54 -07:00
|
|
|
BOOST_STATIC_ASSERT(std::is_constructible<request<one_arg_body>,
|
|
|
|
|
verb, string_view, unsigned, Arg1 const&>::value);
|
2016-05-07 15:18:22 -04:00
|
|
|
|
2017-07-03 20:33:54 -07:00
|
|
|
// 1-arg + fields
|
|
|
|
|
BOOST_STATIC_ASSERT(std::is_constructible<request<one_arg_body>,
|
|
|
|
|
verb, string_view, unsigned, Arg1, fields::allocator_type>::value);
|
2016-05-07 15:18:22 -04:00
|
|
|
|
2017-07-03 20:33:54 -07:00
|
|
|
BOOST_STATIC_ASSERT(std::is_constructible<request<one_arg_body>, std::piecewise_construct_t,
|
|
|
|
|
std::tuple<Arg1>>::value);
|
2016-05-07 15:18:22 -04:00
|
|
|
|
2017-07-03 20:33:54 -07:00
|
|
|
BOOST_STATIC_ASSERT(std::is_constructible<request<two_arg_body>, std::piecewise_construct_t,
|
|
|
|
|
std::tuple<Arg1, Arg2>>::value);
|
2016-05-07 15:18:22 -04:00
|
|
|
|
2017-07-03 20:33:54 -07:00
|
|
|
BOOST_STATIC_ASSERT(std::is_constructible<request<two_arg_body>, std::piecewise_construct_t,
|
|
|
|
|
std::tuple<Arg1, Arg2>, std::tuple<fields::allocator_type>>::value);
|
2016-05-07 15:18:22 -04:00
|
|
|
|
2017-07-03 20:33:54 -07:00
|
|
|
// special members
|
|
|
|
|
BOOST_STATIC_ASSERT(std::is_copy_constructible<header<true>>::value);
|
|
|
|
|
BOOST_STATIC_ASSERT(std::is_move_constructible<header<true>>::value);
|
|
|
|
|
BOOST_STATIC_ASSERT(std::is_copy_assignable<header<true>>::value);
|
|
|
|
|
BOOST_STATIC_ASSERT(std::is_move_assignable<header<true>>::value);
|
|
|
|
|
BOOST_STATIC_ASSERT(std::is_copy_constructible<header<false>>::value);
|
|
|
|
|
BOOST_STATIC_ASSERT(std::is_move_constructible<header<false>>::value);
|
|
|
|
|
BOOST_STATIC_ASSERT(std::is_copy_assignable<header<false>>::value);
|
|
|
|
|
BOOST_STATIC_ASSERT(std::is_move_assignable<header<false>>::value);
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
testMessage()
|
|
|
|
|
{
|
2016-05-07 15:18:22 -04:00
|
|
|
{
|
|
|
|
|
Arg1 arg1;
|
2017-07-03 20:33:54 -07:00
|
|
|
request<one_arg_body>{verb::get, "/", 11, std::move(arg1)};
|
2017-07-25 12:35:54 -07:00
|
|
|
BEAST_EXPECT(arg1.moved);
|
2016-05-07 15:18:22 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
{
|
2017-06-07 16:30:49 -07:00
|
|
|
header<true> h;
|
2017-07-03 20:33:54 -07:00
|
|
|
h.set(field::user_agent, "test");
|
2017-07-25 12:35:54 -07:00
|
|
|
BEAST_EXPECT(h[field::user_agent] == "test");
|
2017-07-03 20:33:54 -07:00
|
|
|
request<default_body> m{std::move(h)};
|
2017-07-25 12:35:54 -07:00
|
|
|
BEAST_EXPECT(m[field::user_agent] == "test");
|
|
|
|
|
BEAST_EXPECT(h.count(field::user_agent) == 0);
|
2016-05-07 15:18:22 -04:00
|
|
|
}
|
|
|
|
|
{
|
2017-07-03 20:33:54 -07:00
|
|
|
request<empty_body> h{verb::get, "/", 10};
|
|
|
|
|
h.set(field::user_agent, "test");
|
|
|
|
|
request<one_arg_body> m{std::move(h.base()), Arg1{}};
|
2017-07-25 12:35:54 -07:00
|
|
|
BEAST_EXPECT(m["User-Agent"] == "test");
|
|
|
|
|
BEAST_EXPECT(h.count(http::field::user_agent) == 0);
|
|
|
|
|
BEAST_EXPECT(m.method() == verb::get);
|
|
|
|
|
BEAST_EXPECT(m.target() == "/");
|
2017-09-12 13:49:45 -07:00
|
|
|
BEAST_EXPECT(m.version() == 10);
|
2016-05-07 15:18:22 -04:00
|
|
|
}
|
|
|
|
|
|
2016-10-09 06:34:35 -04:00
|
|
|
// swap
|
2017-06-07 16:30:49 -07:00
|
|
|
request<string_body> m1;
|
|
|
|
|
request<string_body> m2;
|
2017-05-02 15:49:22 -07:00
|
|
|
m1.target("u");
|
2017-09-12 12:45:52 -07:00
|
|
|
m1.body() = "1";
|
2017-06-05 19:28:17 -07:00
|
|
|
m1.insert("h", "v");
|
2017-06-06 17:26:11 -07:00
|
|
|
m2.method_string("G");
|
2017-09-12 12:45:52 -07:00
|
|
|
m2.body() = "2";
|
2016-05-28 07:56:38 -04:00
|
|
|
swap(m1, m2);
|
2017-07-25 12:35:54 -07:00
|
|
|
BEAST_EXPECT(m1.method_string() == "G");
|
|
|
|
|
BEAST_EXPECT(m2.method_string().empty());
|
|
|
|
|
BEAST_EXPECT(m1.target().empty());
|
|
|
|
|
BEAST_EXPECT(m2.target() == "u");
|
2017-09-12 12:45:52 -07:00
|
|
|
BEAST_EXPECT(m1.body() == "2");
|
|
|
|
|
BEAST_EXPECT(m2.body() == "1");
|
2017-07-25 12:35:54 -07:00
|
|
|
BEAST_EXPECT(! m1.count("h"));
|
|
|
|
|
BEAST_EXPECT(m2.count("h"));
|
2016-05-28 07:56:38 -04:00
|
|
|
}
|
|
|
|
|
|
2017-05-02 15:49:22 -07:00
|
|
|
struct MoveFields : fields
|
2016-10-09 06:34:35 -04:00
|
|
|
{
|
|
|
|
|
bool moved_to = false;
|
|
|
|
|
bool moved_from = false;
|
|
|
|
|
|
2017-05-02 15:49:22 -07:00
|
|
|
MoveFields() = default;
|
2016-10-09 06:34:35 -04:00
|
|
|
|
2017-05-02 15:49:22 -07:00
|
|
|
MoveFields(MoveFields&& other)
|
2016-10-09 06:34:35 -04:00
|
|
|
: moved_to(true)
|
|
|
|
|
{
|
|
|
|
|
other.moved_from = true;
|
|
|
|
|
}
|
|
|
|
|
|
2017-06-22 10:27:45 -07:00
|
|
|
MoveFields& operator=(MoveFields&&)
|
2016-10-09 06:34:35 -04:00
|
|
|
{
|
|
|
|
|
return *this;
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2017-07-03 20:33:54 -07:00
|
|
|
struct token {};
|
|
|
|
|
|
|
|
|
|
struct test_fields
|
|
|
|
|
{
|
|
|
|
|
std::string target;
|
|
|
|
|
|
|
|
|
|
test_fields() = delete;
|
|
|
|
|
test_fields(token) {}
|
|
|
|
|
string_view get_method_impl() const { return {}; }
|
|
|
|
|
string_view get_target_impl() const { return target; }
|
|
|
|
|
string_view get_reason_impl() const { return {}; }
|
2017-07-09 05:26:27 -07:00
|
|
|
bool get_chunked_impl() const { return false; }
|
|
|
|
|
bool get_keep_alive_impl(unsigned) const { return true; }
|
2017-10-25 17:47:12 -07:00
|
|
|
bool has_content_length_impl() const { return false; }
|
2017-07-09 05:26:27 -07:00
|
|
|
void set_method_impl(string_view) {}
|
2019-02-07 23:47:05 +01:00
|
|
|
void set_target_impl(string_view s) { target = std::string(s); }
|
2017-07-09 05:26:27 -07:00
|
|
|
void set_reason_impl(string_view) {}
|
|
|
|
|
void set_chunked_impl(bool) {}
|
|
|
|
|
void set_content_length_impl(boost::optional<std::uint64_t>) {}
|
|
|
|
|
void set_keep_alive_impl(unsigned, bool) {}
|
2017-07-03 20:33:54 -07:00
|
|
|
};
|
|
|
|
|
|
2017-05-02 15:49:22 -07:00
|
|
|
void
|
2017-07-03 20:33:54 -07:00
|
|
|
testMessageCtors()
|
2016-10-09 06:34:35 -04:00
|
|
|
{
|
|
|
|
|
{
|
2017-07-03 20:33:54 -07:00
|
|
|
request<empty_body> req;
|
2017-09-12 13:49:45 -07:00
|
|
|
BEAST_EXPECT(req.version() == 11);
|
2017-07-25 12:35:54 -07:00
|
|
|
BEAST_EXPECT(req.method() == verb::unknown);
|
|
|
|
|
BEAST_EXPECT(req.target() == "");
|
2017-07-03 20:33:54 -07:00
|
|
|
}
|
|
|
|
|
{
|
|
|
|
|
request<empty_body> req{verb::get, "/", 11};
|
2017-09-12 13:49:45 -07:00
|
|
|
BEAST_EXPECT(req.version() == 11);
|
2017-07-25 12:35:54 -07:00
|
|
|
BEAST_EXPECT(req.method() == verb::get);
|
|
|
|
|
BEAST_EXPECT(req.target() == "/");
|
2017-07-03 20:33:54 -07:00
|
|
|
}
|
|
|
|
|
{
|
|
|
|
|
request<string_body> req{verb::get, "/", 11, "Hello"};
|
2017-09-12 13:49:45 -07:00
|
|
|
BEAST_EXPECT(req.version() == 11);
|
2017-07-25 12:35:54 -07:00
|
|
|
BEAST_EXPECT(req.method() == verb::get);
|
|
|
|
|
BEAST_EXPECT(req.target() == "/");
|
2017-09-12 12:45:52 -07:00
|
|
|
BEAST_EXPECT(req.body() == "Hello");
|
2017-07-03 20:33:54 -07:00
|
|
|
}
|
|
|
|
|
{
|
|
|
|
|
request<string_body, test_fields> req{
|
|
|
|
|
verb::get, "/", 11, "Hello", token{}};
|
2017-09-12 13:49:45 -07:00
|
|
|
BEAST_EXPECT(req.version() == 11);
|
2017-07-25 12:35:54 -07:00
|
|
|
BEAST_EXPECT(req.method() == verb::get);
|
|
|
|
|
BEAST_EXPECT(req.target() == "/");
|
2017-09-12 12:45:52 -07:00
|
|
|
BEAST_EXPECT(req.body() == "Hello");
|
2017-10-25 17:47:12 -07:00
|
|
|
BEAST_EXPECT(! req.has_content_length());
|
2017-07-03 20:33:54 -07:00
|
|
|
}
|
|
|
|
|
{
|
|
|
|
|
response<string_body> res;
|
2017-09-12 13:49:45 -07:00
|
|
|
BEAST_EXPECT(res.version() == 11);
|
2017-07-25 12:35:54 -07:00
|
|
|
BEAST_EXPECT(res.result() == status::ok);
|
|
|
|
|
BEAST_EXPECT(res.reason() == "OK");
|
2017-07-03 20:33:54 -07:00
|
|
|
}
|
|
|
|
|
{
|
|
|
|
|
response<string_body> res{status::bad_request, 10};
|
2017-09-12 13:49:45 -07:00
|
|
|
BEAST_EXPECT(res.version() == 10);
|
2017-07-25 12:35:54 -07:00
|
|
|
BEAST_EXPECT(res.result() == status::bad_request);
|
|
|
|
|
BEAST_EXPECT(res.reason() == "Bad Request");
|
2017-07-03 20:33:54 -07:00
|
|
|
}
|
|
|
|
|
{
|
|
|
|
|
response<string_body> res{status::bad_request, 10, "Hello"};
|
2017-09-12 13:49:45 -07:00
|
|
|
BEAST_EXPECT(res.version() == 10);
|
2017-07-25 12:35:54 -07:00
|
|
|
BEAST_EXPECT(res.result() == status::bad_request);
|
|
|
|
|
BEAST_EXPECT(res.reason() == "Bad Request");
|
2017-09-12 12:45:52 -07:00
|
|
|
BEAST_EXPECT(res.body() == "Hello");
|
2016-10-09 06:34:35 -04:00
|
|
|
}
|
|
|
|
|
{
|
2017-07-03 20:33:54 -07:00
|
|
|
response<string_body, test_fields> res{
|
|
|
|
|
status::bad_request, 10, "Hello", token{}};
|
2017-09-12 13:49:45 -07:00
|
|
|
BEAST_EXPECT(res.version() == 10);
|
2017-07-25 12:35:54 -07:00
|
|
|
BEAST_EXPECT(res.result() == status::bad_request);
|
|
|
|
|
BEAST_EXPECT(res.reason() == "Bad Request");
|
2017-09-12 12:45:52 -07:00
|
|
|
BEAST_EXPECT(res.body() == "Hello");
|
2017-10-25 17:47:12 -07:00
|
|
|
BEAST_EXPECT(! res.has_content_length());
|
2016-10-09 06:34:35 -04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-10-30 14:45:16 -07:00
|
|
|
void
|
|
|
|
|
testBody()
|
|
|
|
|
{
|
|
|
|
|
{
|
|
|
|
|
auto f = [](empty_body::value_type&){};
|
|
|
|
|
request<empty_body> m;
|
|
|
|
|
f(m.body());
|
|
|
|
|
}
|
|
|
|
|
{
|
|
|
|
|
auto f = [](empty_body::value_type const&){};
|
2017-10-31 14:43:10 -07:00
|
|
|
request<empty_body> const m{};
|
2017-10-30 14:45:16 -07:00
|
|
|
f(m.body());
|
|
|
|
|
f(std::move(m.body()));
|
|
|
|
|
}
|
|
|
|
|
{
|
|
|
|
|
auto f = [](empty_body::value_type&&){};
|
|
|
|
|
request<empty_body> m;
|
|
|
|
|
f(std::move(m).body());
|
|
|
|
|
f(std::move(m.body()));
|
|
|
|
|
}
|
|
|
|
|
{
|
|
|
|
|
auto f = [](empty_body::value_type const&&){};
|
2017-10-31 14:43:10 -07:00
|
|
|
request<empty_body> const m{};
|
2017-10-30 14:45:16 -07:00
|
|
|
f(std::move(m.body()));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-05-02 15:49:22 -07:00
|
|
|
void
|
|
|
|
|
testSwap()
|
2016-10-09 06:34:35 -04:00
|
|
|
{
|
2017-06-07 16:30:49 -07:00
|
|
|
response<string_body> m1;
|
|
|
|
|
response<string_body> m2;
|
2017-06-04 12:38:42 -07:00
|
|
|
m1.result(status::ok);
|
2017-09-12 13:49:45 -07:00
|
|
|
m1.version(10);
|
2017-09-12 12:45:52 -07:00
|
|
|
m1.body() = "1";
|
2017-06-05 19:28:17 -07:00
|
|
|
m1.insert("h", "v");
|
2017-06-04 12:38:42 -07:00
|
|
|
m2.result(status::not_found);
|
2017-09-12 12:45:52 -07:00
|
|
|
m2.body() = "2";
|
2017-09-12 13:49:45 -07:00
|
|
|
m2.version(11);
|
2016-10-09 06:34:35 -04:00
|
|
|
swap(m1, m2);
|
2017-07-25 12:35:54 -07:00
|
|
|
BEAST_EXPECT(m1.result() == status::not_found);
|
|
|
|
|
BEAST_EXPECT(m1.result_int() == 404);
|
|
|
|
|
BEAST_EXPECT(m2.result() == status::ok);
|
|
|
|
|
BEAST_EXPECT(m2.result_int() == 200);
|
|
|
|
|
BEAST_EXPECT(m1.reason() == "Not Found");
|
|
|
|
|
BEAST_EXPECT(m2.reason() == "OK");
|
2017-09-12 13:49:45 -07:00
|
|
|
BEAST_EXPECT(m1.version() == 11);
|
|
|
|
|
BEAST_EXPECT(m2.version() == 10);
|
2017-09-12 12:45:52 -07:00
|
|
|
BEAST_EXPECT(m1.body() == "2");
|
|
|
|
|
BEAST_EXPECT(m2.body() == "1");
|
2017-07-25 12:35:54 -07:00
|
|
|
BEAST_EXPECT(! m1.count("h"));
|
|
|
|
|
BEAST_EXPECT(m2.count("h"));
|
2016-10-09 06:34:35 -04:00
|
|
|
}
|
|
|
|
|
|
2016-11-20 07:35:27 -05:00
|
|
|
void
|
|
|
|
|
testSpecialMembers()
|
|
|
|
|
{
|
|
|
|
|
response<string_body> r1;
|
|
|
|
|
response<string_body> r2{r1};
|
|
|
|
|
response<string_body> r3{std::move(r2)};
|
|
|
|
|
r2 = r3;
|
|
|
|
|
r1 = std::move(r2);
|
|
|
|
|
[r1]()
|
|
|
|
|
{
|
|
|
|
|
}();
|
|
|
|
|
}
|
|
|
|
|
|
2017-06-04 10:03:36 -07:00
|
|
|
void
|
|
|
|
|
testMethod()
|
|
|
|
|
{
|
|
|
|
|
header<true> h;
|
|
|
|
|
auto const vcheck =
|
|
|
|
|
[&](verb v)
|
|
|
|
|
{
|
|
|
|
|
h.method(v);
|
2017-07-25 12:35:54 -07:00
|
|
|
BEAST_EXPECT(h.method() == v);
|
|
|
|
|
BEAST_EXPECT(h.method_string() == to_string(v));
|
2017-06-04 10:03:36 -07:00
|
|
|
};
|
|
|
|
|
auto const scheck =
|
|
|
|
|
[&](string_view s)
|
|
|
|
|
{
|
2017-06-06 17:26:11 -07:00
|
|
|
h.method_string(s);
|
2017-07-25 12:35:54 -07:00
|
|
|
BEAST_EXPECT(h.method() == string_to_verb(s));
|
|
|
|
|
BEAST_EXPECT(h.method_string() == s);
|
2017-06-04 10:03:36 -07:00
|
|
|
};
|
|
|
|
|
vcheck(verb::get);
|
|
|
|
|
vcheck(verb::head);
|
|
|
|
|
scheck("GET");
|
|
|
|
|
scheck("HEAD");
|
|
|
|
|
scheck("XYZ");
|
|
|
|
|
}
|
|
|
|
|
|
2017-06-04 12:38:42 -07:00
|
|
|
void
|
|
|
|
|
testStatus()
|
|
|
|
|
{
|
|
|
|
|
header<false> h;
|
|
|
|
|
h.result(200);
|
2017-07-25 12:35:54 -07:00
|
|
|
BEAST_EXPECT(h.result_int() == 200);
|
|
|
|
|
BEAST_EXPECT(h.result() == status::ok);
|
2017-06-04 12:38:42 -07:00
|
|
|
h.result(status::switching_protocols);
|
2017-07-25 12:35:54 -07:00
|
|
|
BEAST_EXPECT(h.result_int() == 101);
|
|
|
|
|
BEAST_EXPECT(h.result() == status::switching_protocols);
|
2017-06-04 12:38:42 -07:00
|
|
|
h.result(1);
|
2017-07-25 12:35:54 -07:00
|
|
|
BEAST_EXPECT(h.result_int() == 1);
|
|
|
|
|
BEAST_EXPECT(h.result() == status::unknown);
|
2017-06-04 12:38:42 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
testReason()
|
|
|
|
|
{
|
|
|
|
|
header<false> h;
|
|
|
|
|
h.result(status::ok);
|
2017-07-25 12:35:54 -07:00
|
|
|
BEAST_EXPECT(h.reason() == "OK");
|
2017-06-04 12:38:42 -07:00
|
|
|
h.reason("Pepe");
|
2017-07-25 12:35:54 -07:00
|
|
|
BEAST_EXPECT(h.reason() == "Pepe");
|
2017-06-04 12:38:42 -07:00
|
|
|
h.result(status::not_found);
|
2017-07-25 12:35:54 -07:00
|
|
|
BEAST_EXPECT(h.reason() == "Pepe");
|
2017-06-04 12:38:42 -07:00
|
|
|
h.reason({});
|
2017-07-25 12:35:54 -07:00
|
|
|
BEAST_EXPECT(h.reason() == "Not Found");
|
2017-06-04 12:38:42 -07:00
|
|
|
}
|
|
|
|
|
|
2017-10-25 18:41:04 -07:00
|
|
|
void
|
|
|
|
|
testNeedEof()
|
|
|
|
|
{
|
|
|
|
|
{
|
|
|
|
|
request<empty_body> m;
|
|
|
|
|
|
|
|
|
|
m.version(10);
|
|
|
|
|
m.keep_alive(false);
|
|
|
|
|
BEAST_EXPECT(m.need_eof());
|
|
|
|
|
m.keep_alive(true);
|
|
|
|
|
BEAST_EXPECT(! m.need_eof());
|
|
|
|
|
|
|
|
|
|
m.version(11);
|
|
|
|
|
m.keep_alive(false);
|
|
|
|
|
BEAST_EXPECT(m.need_eof());
|
|
|
|
|
m.keep_alive(true);
|
|
|
|
|
BEAST_EXPECT(! m.need_eof());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
response<empty_body> m;
|
|
|
|
|
m.result(status::ok);
|
|
|
|
|
|
|
|
|
|
m.version(10);
|
|
|
|
|
m.keep_alive(false);
|
|
|
|
|
BEAST_EXPECT(! m.has_content_length());
|
|
|
|
|
BEAST_EXPECT(! m.chunked());
|
|
|
|
|
m.result(status::no_content);
|
|
|
|
|
BEAST_EXPECT(m.need_eof());
|
|
|
|
|
m.result(status::not_modified);
|
|
|
|
|
BEAST_EXPECT(m.need_eof());
|
|
|
|
|
m.result(status::continue_);
|
|
|
|
|
BEAST_EXPECT(m.need_eof());
|
|
|
|
|
m.result(status::switching_protocols);
|
|
|
|
|
BEAST_EXPECT(m.need_eof());
|
|
|
|
|
m.result(status::ok);
|
|
|
|
|
BEAST_EXPECT(m.need_eof());
|
|
|
|
|
|
|
|
|
|
m.version(10);
|
|
|
|
|
m.keep_alive(true);
|
|
|
|
|
BEAST_EXPECT(! m.has_content_length());
|
|
|
|
|
BEAST_EXPECT(! m.chunked());
|
|
|
|
|
m.result(status::no_content);
|
|
|
|
|
BEAST_EXPECT(! m.need_eof());
|
|
|
|
|
m.result(status::not_modified);
|
|
|
|
|
BEAST_EXPECT(! m.need_eof());
|
|
|
|
|
m.result(status::continue_);
|
|
|
|
|
BEAST_EXPECT(! m.need_eof());
|
|
|
|
|
m.result(status::switching_protocols);
|
|
|
|
|
BEAST_EXPECT(! m.need_eof());
|
|
|
|
|
m.result(status::ok);
|
|
|
|
|
BEAST_EXPECT(m.need_eof());
|
|
|
|
|
m.set(field::content_length, "1");
|
|
|
|
|
BEAST_EXPECT(! m.need_eof());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
response<empty_body> m;
|
|
|
|
|
m.result(status::ok);
|
|
|
|
|
|
|
|
|
|
m.version(11);
|
|
|
|
|
m.keep_alive(false);
|
|
|
|
|
BEAST_EXPECT(! m.has_content_length());
|
|
|
|
|
BEAST_EXPECT(! m.chunked());
|
|
|
|
|
m.result(status::no_content);
|
|
|
|
|
BEAST_EXPECT(m.need_eof());
|
|
|
|
|
m.result(status::not_modified);
|
|
|
|
|
BEAST_EXPECT(m.need_eof());
|
|
|
|
|
m.result(status::continue_);
|
|
|
|
|
BEAST_EXPECT(m.need_eof());
|
|
|
|
|
m.result(status::switching_protocols);
|
|
|
|
|
BEAST_EXPECT(m.need_eof());
|
|
|
|
|
m.result(status::ok);
|
|
|
|
|
BEAST_EXPECT(m.need_eof());
|
|
|
|
|
m.chunked(true);
|
|
|
|
|
BEAST_EXPECT(m.need_eof());
|
|
|
|
|
m.content_length(1);
|
|
|
|
|
BEAST_EXPECT(m.need_eof());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
response<empty_body> m;
|
|
|
|
|
m.result(status::ok);
|
|
|
|
|
|
|
|
|
|
m.version(11);
|
|
|
|
|
m.keep_alive(true);
|
|
|
|
|
BEAST_EXPECT(! m.has_content_length());
|
|
|
|
|
BEAST_EXPECT(! m.chunked());
|
|
|
|
|
m.result(status::no_content);
|
|
|
|
|
BEAST_EXPECT(! m.need_eof());
|
|
|
|
|
m.result(status::not_modified);
|
|
|
|
|
BEAST_EXPECT(! m.need_eof());
|
|
|
|
|
m.result(status::continue_);
|
|
|
|
|
BEAST_EXPECT(! m.need_eof());
|
|
|
|
|
m.result(status::switching_protocols);
|
|
|
|
|
BEAST_EXPECT(! m.need_eof());
|
|
|
|
|
m.result(status::ok);
|
|
|
|
|
BEAST_EXPECT(m.need_eof());
|
|
|
|
|
m.chunked(true);
|
|
|
|
|
BEAST_EXPECT(! m.need_eof());
|
|
|
|
|
m.content_length(1);
|
|
|
|
|
BEAST_EXPECT(! m.need_eof());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-05-02 15:49:22 -07:00
|
|
|
void
|
|
|
|
|
run() override
|
2016-05-07 15:18:22 -04:00
|
|
|
{
|
2016-10-09 06:34:35 -04:00
|
|
|
testMessage();
|
2017-07-03 20:33:54 -07:00
|
|
|
testMessageCtors();
|
2017-10-30 14:45:16 -07:00
|
|
|
testBody();
|
2016-05-28 07:56:38 -04:00
|
|
|
testSwap();
|
2016-11-20 07:35:27 -05:00
|
|
|
testSpecialMembers();
|
2017-06-04 10:03:36 -07:00
|
|
|
testMethod();
|
2017-06-04 12:38:42 -07:00
|
|
|
testStatus();
|
|
|
|
|
testReason();
|
2017-10-25 18:41:04 -07:00
|
|
|
testNeedEof();
|
2016-05-07 15:18:22 -04:00
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2017-08-01 17:01:57 -07:00
|
|
|
BEAST_DEFINE_TESTSUITE(beast,http,message);
|
2016-05-07 15:18:22 -04:00
|
|
|
|
|
|
|
|
} // http
|
|
|
|
|
} // beast
|
2017-07-20 13:40:34 -07:00
|
|
|
} // boost
|