@@ -58,6 +58,15 @@ class simple_resource : public http_resource
5858 }
5959};
6060
61+ class args_resource : public http_resource
62+ {
63+ public:
64+ const http_response render_GET (const http_request& req)
65+ {
66+ return http_response_builder (req.get_arg (" arg" ), 200 , " text/plain" ).string_response ();
67+ }
68+ };
69+
6170class long_content_resource : public http_resource
6271{
6372 public:
@@ -428,6 +437,79 @@ LT_BEGIN_AUTO_TEST(basic_suite, no_response)
428437 curl_easy_cleanup (curl);
429438LT_END_AUTO_TEST (no_response)
430439
440+ LT_BEGIN_AUTO_TEST(basic_suite, regex_matching)
441+ simple_resource* resource = new simple_resource();
442+ ws->register_resource (" regex/matching/number/[0-9]+" , resource);
443+ curl_global_init (CURL_GLOBAL_ALL);
444+
445+ std::string s;
446+ CURL *curl = curl_easy_init();
447+ CURLcode res;
448+ curl_easy_setopt (curl, CURLOPT_URL, " localhost:8080/regex/matching/number/10" );
449+ curl_easy_setopt (curl, CURLOPT_HTTPGET, 1L );
450+ curl_easy_setopt (curl, CURLOPT_WRITEFUNCTION, writefunc);
451+ curl_easy_setopt (curl, CURLOPT_WRITEDATA, &s);
452+ res = curl_easy_perform(curl);
453+ LT_ASSERT_EQ (res, 0 );
454+ LT_CHECK_EQ (s, " OK" );
455+ curl_easy_cleanup (curl);
456+ LT_END_AUTO_TEST (regex_matching)
457+
458+ LT_BEGIN_AUTO_TEST(basic_suite, regex_matching_arg)
459+ args_resource* resource = new args_resource();
460+ ws->register_resource (" this/captures/{arg}/passed/in/input" , resource);
461+ curl_global_init (CURL_GLOBAL_ALL);
462+
463+ std::string s;
464+ CURL *curl = curl_easy_init();
465+ CURLcode res;
466+ curl_easy_setopt (curl, CURLOPT_URL, " localhost:8080/this/captures/whatever/passed/in/input" );
467+ curl_easy_setopt (curl, CURLOPT_HTTPGET, 1L );
468+ curl_easy_setopt (curl, CURLOPT_WRITEFUNCTION, writefunc);
469+ curl_easy_setopt (curl, CURLOPT_WRITEDATA, &s);
470+ res = curl_easy_perform(curl);
471+ LT_ASSERT_EQ (res, 0 );
472+ LT_CHECK_EQ (s, " whatever" );
473+ curl_easy_cleanup (curl);
474+ LT_END_AUTO_TEST (regex_matching_arg)
475+
476+ LT_BEGIN_AUTO_TEST(basic_suite, regex_matching_arg_custom)
477+ args_resource* resource = new args_resource();
478+ ws->register_resource (" this/captures/numeric/{arg|([0-9]+)}/passed/in/input" , resource);
479+ curl_global_init (CURL_GLOBAL_ALL);
480+
481+ {
482+ std::string s;
483+ CURL *curl = curl_easy_init ();
484+ CURLcode res;
485+ curl_easy_setopt (curl, CURLOPT_URL, " localhost:8080/this/captures/numeric/11/passed/in/input" );
486+ curl_easy_setopt (curl, CURLOPT_HTTPGET, 1L );
487+ curl_easy_setopt (curl, CURLOPT_WRITEFUNCTION, writefunc);
488+ curl_easy_setopt (curl, CURLOPT_WRITEDATA, &s);
489+ res = curl_easy_perform (curl);
490+ LT_ASSERT_EQ (res, 0 );
491+ LT_CHECK_EQ (s, " 11" );
492+ curl_easy_cleanup (curl);
493+ }
494+
495+ {
496+ std::string s;
497+ CURL *curl = curl_easy_init ();
498+ CURLcode res;
499+ curl_easy_setopt (curl, CURLOPT_URL, " localhost:8080/this/captures/numeric/text/passed/in/input" );
500+ curl_easy_setopt (curl, CURLOPT_HTTPGET, 1L );
501+ curl_easy_setopt (curl, CURLOPT_WRITEFUNCTION, writefunc);
502+ curl_easy_setopt (curl, CURLOPT_WRITEDATA, &s);
503+ res = curl_easy_perform (curl);
504+ LT_ASSERT_EQ (res, 0 );
505+ LT_CHECK_EQ (s, " Not Found" );
506+ long http_code = 0 ;
507+ curl_easy_getinfo (curl, CURLINFO_RESPONSE_CODE, &http_code);
508+ LT_ASSERT_EQ (http_code, 404 );
509+ curl_easy_cleanup (curl);
510+ }
511+ LT_END_AUTO_TEST (regex_matching_arg_custom)
512+
431513LT_BEGIN_AUTO_TEST_ENV()
432514 AUTORUN_TESTS()
433515LT_END_AUTO_TEST_ENV()
0 commit comments