Browse Source

Added test for post request with query string and body

yhirose 6 years ago
parent
commit
aa543240db
1 changed files with 13 additions and 0 deletions
  1. 13 0
      test/test.cc

+ 13 - 0
test/test.cc

@@ -904,6 +904,12 @@ protected:
                  EXPECT_EQ(body, "content");
                  EXPECT_EQ(body, "content");
                  res.set_content(body, "text/plain");
                  res.set_content(body, "text/plain");
                })
                })
+        .Post("/query-string-and-body",
+              [&](const Request &req, Response & /*res*/) {
+                ASSERT_TRUE(req.has_param("key"));
+                EXPECT_EQ(req.get_param_value("key"), "value");
+                EXPECT_EQ(req.body, "content");
+              })
 #ifdef CPPHTTPLIB_ZLIB_SUPPORT
 #ifdef CPPHTTPLIB_ZLIB_SUPPORT
         .Get("/gzip",
         .Get("/gzip",
              [&](const Request & /*req*/, Response &res) {
              [&](const Request & /*req*/, Response &res) {
@@ -1674,6 +1680,12 @@ TEST_F(ServerTest, PatchContentReceiver) {
   ASSERT_EQ("content", res->body);
   ASSERT_EQ("content", res->body);
 }
 }
 
 
+TEST_F(ServerTest, PostQueryStringAndBody) {
+  auto res = cli_.Post("/query-string-and-body?key=value", "content", "text/plain");
+  ASSERT_TRUE(res != nullptr);
+  ASSERT_EQ(200, res->status);
+}
+
 TEST_F(ServerTest, HTTP2Magic) {
 TEST_F(ServerTest, HTTP2Magic) {
   Request req;
   Request req;
   req.method = "PRI";
   req.method = "PRI";
@@ -1686,6 +1698,7 @@ TEST_F(ServerTest, HTTP2Magic) {
   ASSERT_TRUE(ret);
   ASSERT_TRUE(ret);
   EXPECT_EQ(400, res->status);
   EXPECT_EQ(400, res->status);
 }
 }
+
 TEST_F(ServerTest, KeepAlive) {
 TEST_F(ServerTest, KeepAlive) {
   cli_.set_keep_alive_max_count(4);
   cli_.set_keep_alive_max_count(4);