aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authoripknHama <ipknhama@gmail.com>2014-10-07 21:51:24 +0900
committeripknHama <ipknhama@gmail.com>2014-10-07 21:51:24 +0900
commita5fab23f70e6e33c633ba4b646a41d0851169ad1 (patch)
tree78a80f28adf2e145e061ee0a04e5ffc8fa915a1d /tests
parentd496f0f4b5a4f154ffdb89896d8de155a002c393 (diff)
downloadcrow-a5fab23f70e6e33c633ba4b646a41d0851169ad1.tar.gz
crow-a5fab23f70e6e33c633ba4b646a41d0851169ad1.zip
HTTP GET/POST method distinguish
Diffstat (limited to 'tests')
-rw-r--r--tests/unittest.cpp78
1 files changed, 75 insertions, 3 deletions
diff --git a/tests/unittest.cpp b/tests/unittest.cpp
index 818032f..dc04a5f 100644
--- a/tests/unittest.cpp
+++ b/tests/unittest.cpp
@@ -249,6 +249,79 @@ TEST(handler_with_response)
});
}
+TEST(http_method)
+{
+ SimpleApp app;
+
+ CROW_ROUTE(app, "/")
+ .methods("POST"_method, "GET"_method)
+ ([](const request& req){
+ if (req.method == "GET"_method)
+ return "2";
+ else
+ return "1";
+ });
+
+ CROW_ROUTE(app, "/get_only")
+ .methods("GET"_method)
+ ([](const request& req){
+ return "get";
+ });
+ CROW_ROUTE(app, "/post_only")
+ .methods("POST"_method)
+ ([](const request& req){
+ return "post";
+ });
+
+
+ // cannot have multiple handlers for the same url
+ //CROW_ROUTE(app, "/")
+ //.methods("GET"_method)
+ //([]{ return "2"; });
+
+ {
+ request req;
+ response res;
+
+ req.url = "/";
+ app.handle(req, res);
+
+ ASSERT_EQUAL("2", res.body);
+ }
+ {
+ request req;
+ response res;
+
+ req.url = "/";
+ req.method = "POST"_method;
+ app.handle(req, res);
+
+ ASSERT_EQUAL("1", res.body);
+ }
+
+ {
+ request req;
+ response res;
+
+ req.url = "/get_only";
+ app.handle(req, res);
+
+ ASSERT_EQUAL("get", res.body);
+ }
+
+ {
+ request req;
+ response res;
+
+ req.url = "/get_only";
+ req.method = "POST"_method;
+ app.handle(req, res);
+
+ ASSERT_NOTEQUAL("get", res.body);
+ }
+
+}
+
TEST(server_handling_error_request)
{
static char buf[2048];
@@ -282,8 +355,8 @@ TEST(multi_server)
{
static char buf[2048];
SimpleApp app1, app2;
- CROW_ROUTE(app1, "/")([]{return "A";});
- CROW_ROUTE(app2, "/")([]{return "B";});
+ CROW_ROUTE(app1, "/").methods("GET"_method, "POST"_method)([]{return "A";});
+ CROW_ROUTE(app2, "/").methods("GET"_method, "POST"_method)([]{return "B";});
Server<SimpleApp> server1(&app1, 45451);
Server<SimpleApp> server2(&app2, 45452);
@@ -297,7 +370,6 @@ TEST(multi_server)
asio::ip::tcp::socket c(is);
c.connect(asio::ip::tcp::endpoint(asio::ip::address::from_string("127.0.0.1"), 45451));
-
c.send(asio::buffer(sendmsg));
size_t recved = c.receive(asio::buffer(buf, 2048));