Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/details/http_endpoint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ http_endpoint& http_endpoint::operator =(const http_endpoint& h) {
}

bool http_endpoint::operator <(const http_endpoint& b) const {
if (family_url != b.family_url) return family_url;
Comment thread
bcsgh marked this conversation as resolved.
COMPARATOR(url_normalized, b.url_normalized, std::toupper);
}

Expand Down
2 changes: 1 addition & 1 deletion src/webserver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ bool webserver::register_resource(const std::string& resource, http_resource* hr

pair<map<details::http_endpoint, http_resource*>::iterator, bool> result = registered_resources.insert(map<details::http_endpoint, http_resource*>::value_type(idx, hrm));

if (result.second) {
if (!family && result.second) {
registered_resources_str.insert(pair<string, http_resource*>(idx.get_url_complete(), result.first->second));
}

Expand Down
106 changes: 100 additions & 6 deletions test/integ/basic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,7 @@ LT_BEGIN_AUTO_TEST(basic_suite, duplicate_endpoints)
LT_CHECK_EQ(false, ws->register_resource("OK/", &ok2));

// Check how family interacts.
LT_CHECK_EQ(false, ws->register_resource("OK", &ok2, true));
LT_CHECK_EQ(true, ws->register_resource("OK", &ok2, true));

// Check that switched case does the right thing, whatever that is here.
#ifdef CASE_INSENSITIVE
Expand All @@ -406,6 +406,100 @@ LT_BEGIN_AUTO_TEST(basic_suite, duplicate_endpoints)
#endif
LT_END_AUTO_TEST(duplicate_endpoints)

LT_BEGIN_AUTO_TEST(basic_suite, family_endpoints)
static_resource ok1("1"), ok2("2");
LT_CHECK_EQ(true, ws->register_resource("OK", &ok1));
LT_CHECK_EQ(true, ws->register_resource("OK", &ok2, true));

curl_global_init(CURL_GLOBAL_ALL);

{
string s;
CURL *curl = curl_easy_init();
CURLcode res;
curl_easy_setopt(curl, CURLOPT_URL, "localhost:" PORT_STRING "/OK");
curl_easy_setopt(curl, CURLOPT_HTTPGET, 1L);
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, writefunc);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &s);
res = curl_easy_perform(curl);
LT_ASSERT_EQ(res, 0);
LT_CHECK_EQ(s, "1");
curl_easy_cleanup(curl);
}

{
string s;
CURL *curl = curl_easy_init();
CURLcode res;
curl_easy_setopt(curl, CURLOPT_URL, "localhost:" PORT_STRING "/OK/");
curl_easy_setopt(curl, CURLOPT_HTTPGET, 1L);
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, writefunc);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &s);
res = curl_easy_perform(curl);
LT_ASSERT_EQ(res, 0);
LT_CHECK_EQ(s, "1");
curl_easy_cleanup(curl);
}

{
string s;
CURL *curl = curl_easy_init();
CURLcode res;
curl_easy_setopt(curl, CURLOPT_URL, "localhost:" PORT_STRING "/OK/go");
curl_easy_setopt(curl, CURLOPT_HTTPGET, 1L);
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, writefunc);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &s);
res = curl_easy_perform(curl);
LT_ASSERT_EQ(res, 0);
LT_CHECK_EQ(s, "2");
curl_easy_cleanup(curl);
}

#ifdef CASE_INSENSITIVE
{
string s;
CURL *curl = curl_easy_init();
CURLcode res;
curl_easy_setopt(curl, CURLOPT_URL, "localhost:" PORT_STRING "/OK");
curl_easy_setopt(curl, CURLOPT_HTTPGET, 1L);
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, writefunc);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &s);
res = curl_easy_perform(curl);
LT_ASSERT_EQ(res, 0);
LT_CHECK_EQ(s, "1");
curl_easy_cleanup(curl);
}

{
string s;
CURL *curl = curl_easy_init();
CURLcode res;
curl_easy_setopt(curl, CURLOPT_URL, "localhost:" PORT_STRING "/OK/");
curl_easy_setopt(curl, CURLOPT_HTTPGET, 1L);
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, writefunc);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &s);
res = curl_easy_perform(curl);
LT_ASSERT_EQ(res, 0);
LT_CHECK_EQ(s, "1");
curl_easy_cleanup(curl);
}

{
string s;
CURL *curl = curl_easy_init();
CURLcode res;
curl_easy_setopt(curl, CURLOPT_URL, "localhost:" PORT_STRING "/OK/go");
curl_easy_setopt(curl, CURLOPT_HTTPGET, 1L);
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, writefunc);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &s);
res = curl_easy_perform(curl);
LT_ASSERT_EQ(res, 0);
LT_CHECK_EQ(s, "2");
curl_easy_cleanup(curl);
}
#endif
LT_END_AUTO_TEST(family_endpoints)

LT_BEGIN_AUTO_TEST(basic_suite, overlapping_endpoints)
// Setup two different resources that can both match the same URL.
static_resource ok1("1"), ok2("2");
Expand All @@ -418,7 +512,7 @@ LT_BEGIN_AUTO_TEST(basic_suite, overlapping_endpoints)
string s;
CURL *curl = curl_easy_init();
CURLcode res;
curl_easy_setopt(curl, CURLOPT_URL, "localhost:8080/foo/bar/");
curl_easy_setopt(curl, CURLOPT_URL, "localhost:" PORT_STRING "/foo/bar/");
curl_easy_setopt(curl, CURLOPT_HTTPGET, 1L);
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, writefunc);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &s);
Expand All @@ -436,7 +530,7 @@ LT_BEGIN_AUTO_TEST(basic_suite, overlapping_endpoints)
string s;
CURL *curl = curl_easy_init();
CURLcode res;
curl_easy_setopt(curl, CURLOPT_URL, "localhost:8080/foo/bar/");
curl_easy_setopt(curl, CURLOPT_URL, "localhost:" PORT_STRING "/foo/bar/");
curl_easy_setopt(curl, CURLOPT_HTTPGET, 1L);
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, writefunc);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &s);
Expand Down Expand Up @@ -1267,7 +1361,7 @@ LT_BEGIN_AUTO_TEST(basic_suite, non_family_url_with_regex_like_pieces)
string s;
CURL *curl = curl_easy_init();
CURLcode res;
curl_easy_setopt(curl, CURLOPT_URL, "localhost:8080/settings/{}");
curl_easy_setopt(curl, CURLOPT_URL, "localhost:" PORT_STRING "/settings/{}");
curl_easy_setopt(curl, CURLOPT_HTTPGET, 1L);
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, writefunc);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &s);
Expand All @@ -1290,7 +1384,7 @@ LT_BEGIN_AUTO_TEST(basic_suite, regex_url_exact_match)
string s;
CURL *curl = curl_easy_init();
CURLcode res;
curl_easy_setopt(curl, CURLOPT_URL, "localhost:8080/foo/a/bar/");
curl_easy_setopt(curl, CURLOPT_URL, "localhost:" PORT_STRING "/foo/a/bar/");
curl_easy_setopt(curl, CURLOPT_HTTPGET, 1L);
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, writefunc);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &s);
Expand All @@ -1309,7 +1403,7 @@ LT_BEGIN_AUTO_TEST(basic_suite, regex_url_exact_match)
string s;
CURL *curl = curl_easy_init();
CURLcode res;
curl_easy_setopt(curl, CURLOPT_URL, "localhost:8080/foo/{v|[a-z]}/bar/");
curl_easy_setopt(curl, CURLOPT_URL, "localhost:" PORT_STRING "/foo/{v|[a-z]}/bar/");
curl_easy_setopt(curl, CURLOPT_HTTPGET, 1L);
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, writefunc);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &s);
Expand Down