4 #include <boost/test/unit_test.hpp> 13 req.method(beast::http::verb::get);
16 req.insert(
"host",
"example.com:80");
17 req.insert(
"user-agent",
"unit test");
20 BOOST_CHECK_EQUAL(res.result_int(), (int)beast::http::status::not_found);
21 BOOST_CHECK_EQUAL(res.version, 11);
22 BOOST_CHECK_EQUAL(res[
"server"],
"test");
25 res.insert(
"content-type",
"text/plain");
29 BOOST_CHECK_EQUAL(res.result_int(), (int)beast::http::status::ok);
30 BOOST_CHECK_EQUAL(res.version, 11);
31 BOOST_CHECK_EQUAL(res[
"server"],
"test");
32 BOOST_CHECK_EQUAL(res.body,
"OK\r\n");
34 req.target(
"/not-there");
36 BOOST_CHECK_EQUAL(res.result_int(), (int)beast::http::status::not_found);
37 BOOST_CHECK_EQUAL(res.version, 11);
38 BOOST_CHECK_EQUAL(res[
"server"],
"test");
42 res.insert(
"content-type",
"text/plain");
43 res.body =
"Fine I guess\r\n";
47 BOOST_CHECK_EQUAL(res.result_int(), (int)beast::http::status::ok);
48 BOOST_CHECK_EQUAL(res.version, 11);
49 BOOST_CHECK_EQUAL(res[
"server"],
"test");
50 BOOST_CHECK_EQUAL(res.body,
"Fine I guess\r\n");
60 throw std::runtime_error(
"bad stuff happens");
65 req.method(beast::http::verb::get);
68 req.insert(
"host",
"example.com:80");
69 req.insert(
"user-agent",
"unit test");
73 res.result_int(), (int)beast::http::status::internal_server_error);
74 BOOST_CHECK_EQUAL(res.version, 11);
75 BOOST_CHECK_EQUAL(res[
"server"],
"test");
77 BOOST_CHECK_THROW(tested.
add_handler(
"/error", thrower), std::runtime_error);
88 if (req.count(
"x-return-status") > 0) {
89 std::string val(req[
"x-return-status"]);
94 BOOST_CHECK_MESSAGE(
false,
"x-return-status not set");
96 res.insert(
"content-type",
"text/plain");
101 req.method(beast::http::verb::get);
104 req.insert(
"host",
"example.com:80");
105 req.insert(
"user-agent",
"unit test");
107 req.insert(
"x-return-status",
"200");
109 BOOST_CHECK_EQUAL(res.result_int(), 200);
112 req.set(
"x-return-status",
"100");
114 BOOST_CHECK_EQUAL(res.result_int(), 100);
117 req.set(
"x-return-status",
"204");
119 BOOST_CHECK_EQUAL(res.result_int(), 204);
122 req.set(
"x-return-status",
"300");
124 BOOST_CHECK_EQUAL(res.result_int(), 300);
127 req.set(
"x-return-status",
"400");
129 BOOST_CHECK_EQUAL(res.result_int(), 400);
132 req.set(
"x-return-status",
"500");
134 BOOST_CHECK_EQUAL(res.result_int(), 500);
137 req.set(
"x-return-status",
"600");
139 BOOST_CHECK_EQUAL(res.result_int(), 600);
211 BOOST_CHECK_NE(res.body,
"");
long get_open_connection() const
Returns the count of open connections.
beast::http::request< beast::http::string_body > request_type
The request type used for JayBeams Embedded HTTP Servers.
void count_write_error()
Count a write errors.
void count_accept_ok()
Count accept successes.
long get_accept_error() const
void count_open_connection()
Event counters.
long get_read_ok() const
Get the count of successful reads.
long get_close_connection() const
Get the count of close connections.
void append_metrics(response_type &res) const
Append the internal metrics to the body of res.
void count_write_ok()
Count a write successes.
Holds a collection of HTTP request handlers and forwards requests.
long get_write_400() const
Get the count write in the 400 range.
beast::http::response< beast::http::string_body > response_type
The response type used for JayBeams Embedded HTTP Servers.
void count_close_connection()
Count a new connection closed.
void count_read_error()
Count a write errors.
long get_write_invalid() const
Get count of responses with invalid codes (outside the [100,600) range).
bool strtonum(std::string const &s, T &r)
Generic string to number conversion with validation.
void count_read_ok()
Count a successful read.
long get_write_100() const
Get the count write in the 100 range.
Contains types and classes to implemented Embedded HTTP Servers.
long get_write_300() const
Get the count write in the 300 range.
long get_accept_ok() const
long get_write_500() const
Get the count write in the 500 range.
long get_read_error() const
Get the count write errors.
long get_write_200() const
Get the count write in the 200 range.
long get_write_error() const
Get the count write errors.
void count_accept_error()
Count accept errors.
response_type process(request_type const &request)
Process a new request using the right handler.
long get_write_ok() const
Get the count write successes.
BOOST_AUTO_TEST_CASE(request_dispatcher_base)
void add_handler(std::string const &path, request_handler &&handler)
Add a new handler.