@@ -3706,25 +3706,59 @@ TEST(GetWithParametersTest, GetWithParameters) {
3706
3706
Server svr;
3707
3707
3708
3708
svr.Get (" /" , [&](const Request &req, Response &res) {
3709
- auto text = req.get_param_value (" hello" );
3710
- res.set_content (text, " text/plain" );
3709
+ EXPECT_EQ (" world" , req.get_param_value (" hello" ));
3710
+ EXPECT_EQ (" world2" , req.get_param_value (" hello2" ));
3711
+ EXPECT_EQ (" world3" , req.get_param_value (" hello3" ));
3711
3712
});
3712
3713
3713
- auto listen_thread = std::thread ([&svr]() { svr.listen (" localhost" , PORT); });
3714
+ svr.Get (" /params" , [&](const Request &req, Response &res) {
3715
+ EXPECT_EQ (" world" , req.get_param_value (" hello" ));
3716
+ EXPECT_EQ (" world2" , req.get_param_value (" hello2" ));
3717
+ EXPECT_EQ (" world3" , req.get_param_value (" hello3" ));
3718
+ });
3719
+
3720
+ svr.Get (R"( /resources/([a-z0-9\\-]+))" , [&](const Request& req, Response& res) {
3721
+ EXPECT_EQ (" resource-id" , req.matches [1 ]);
3722
+ EXPECT_EQ (" foo" , req.get_param_value (" param1" ));
3723
+ EXPECT_EQ (" bar" , req.get_param_value (" param2" ));
3724
+ });
3725
+
3726
+ auto listen_thread = std::thread ([&svr]() { svr.listen (HOST, PORT); });
3714
3727
while (!svr.is_running ()) {
3715
3728
std::this_thread::sleep_for (std::chrono::milliseconds (1 ));
3716
3729
}
3717
3730
std::this_thread::sleep_for (std::chrono::seconds (1 ));
3718
3731
3719
- Client cli (" localhost" , PORT);
3732
+ {
3733
+ Client cli (HOST, PORT);
3720
3734
3721
- Params params;
3722
- params.emplace (" hello" , " world" );
3723
- auto res = cli.Get (" /" , params, Headers{});
3735
+ Params params;
3736
+ params.emplace (" hello" , " world" );
3737
+ params.emplace (" hello2" , " world2" );
3738
+ params.emplace (" hello3" , " world3" );
3739
+ auto res = cli.Get (" /" , params, Headers{});
3724
3740
3725
- ASSERT_TRUE (res);
3726
- EXPECT_EQ (200 , res->status );
3727
- EXPECT_EQ (" world" , res->body );
3741
+ ASSERT_TRUE (res);
3742
+ EXPECT_EQ (200 , res->status );
3743
+ }
3744
+
3745
+ {
3746
+ Client cli (HOST, PORT);
3747
+
3748
+ auto res = cli.Get (" /params?hello=world&hello2=world2&hello3=world3" );
3749
+
3750
+ ASSERT_TRUE (res);
3751
+ EXPECT_EQ (200 , res->status );
3752
+ }
3753
+
3754
+ {
3755
+ Client cli (HOST, PORT);
3756
+
3757
+ auto res = cli.Get (" /resources/resource-id?param1=foo¶m2=bar" );
3758
+
3759
+ ASSERT_TRUE (res);
3760
+ EXPECT_EQ (200 , res->status );
3761
+ }
3728
3762
3729
3763
svr.stop ();
3730
3764
listen_thread.join ();
0 commit comments