@@ -3706,25 +3706,59 @@ TEST(GetWithParametersTest, GetWithParameters) {
37063706 Server svr;
37073707
37083708 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" ));
37113712 });
37123713
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); });
37143727 while (!svr.is_running ()) {
37153728 std::this_thread::sleep_for (std::chrono::milliseconds (1 ));
37163729 }
37173730 std::this_thread::sleep_for (std::chrono::seconds (1 ));
37183731
3719- Client cli (" localhost" , PORT);
3732+ {
3733+ Client cli (HOST, PORT);
37203734
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{});
37243740
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+ }
37283762
37293763 svr.stop ();
37303764 listen_thread.join ();
0 commit comments