nghttpx: Fix path matching bug

Previously, if path is empty or path does not start with "/", nghttpx
did not try to match with wildcard pattern.  This commit fixes it.
This commit is contained in:
Tatsuhiro Tsujikawa 2017-04-18 21:03:50 +09:00
parent 5e00cf9620
commit 0a2d1965df
2 changed files with 16 additions and 12 deletions

View File

@ -505,18 +505,6 @@ size_t match_downstream_addr_group_host(
const auto &rev_wildcard_router = routerconf.rev_wildcard_router; const auto &rev_wildcard_router = routerconf.rev_wildcard_router;
const auto &wildcard_patterns = routerconf.wildcard_patterns; const auto &wildcard_patterns = routerconf.wildcard_patterns;
if (path.empty() || path[0] != '/') {
auto group = router.match(host, StringRef::from_lit("/"));
if (group != -1) {
if (LOG_ENABLED(INFO)) {
LOG(INFO) << "Found pattern with query " << host
<< ", matched pattern=" << groups[group]->pattern;
}
return group;
}
return catch_all;
}
if (LOG_ENABLED(INFO)) { if (LOG_ENABLED(INFO)) {
LOG(INFO) << "Perform mapping selection, using host=" << host LOG(INFO) << "Perform mapping selection, using host=" << host
<< ", path=" << path; << ", path=" << path;
@ -602,6 +590,10 @@ size_t match_downstream_addr_group(
auto query = std::find(std::begin(raw_path), fragment, '?'); auto query = std::find(std::begin(raw_path), fragment, '?');
auto path = StringRef{std::begin(raw_path), query}; auto path = StringRef{std::begin(raw_path), query};
if (path.empty() || path[0] != '/') {
path = StringRef::from_lit("/");
}
if (hostport.empty()) { if (hostport.empty()) {
return match_downstream_addr_group_host(routerconf, hostport, path, groups, return match_downstream_addr_group_host(routerconf, hostport, path, groups,
catch_all, balloc); catch_all, balloc);

View File

@ -197,6 +197,10 @@ void test_shrpx_worker_match_downstream_addr_group(void) {
g2->pattern = ImmutableString::from_lit(".nghttp2.org"); g2->pattern = ImmutableString::from_lit(".nghttp2.org");
groups.push_back(std::move(g2)); groups.push_back(std::move(g2));
auto g3 = std::make_shared<DownstreamAddrGroup>();
g3->pattern = ImmutableString::from_lit(".local");
groups.push_back(std::move(g3));
wp.emplace_back(StringRef::from_lit("git.nghttp2.org")); wp.emplace_back(StringRef::from_lit("git.nghttp2.org"));
wcrouter.add_route(StringRef::from_lit("gro.2ptthgn.tig"), 0); wcrouter.add_route(StringRef::from_lit("gro.2ptthgn.tig"), 0);
wp.back().router.add_route(StringRef::from_lit("/echo/"), 10); wp.back().router.add_route(StringRef::from_lit("/echo/"), 10);
@ -206,6 +210,10 @@ void test_shrpx_worker_match_downstream_addr_group(void) {
wp.back().router.add_route(StringRef::from_lit("/echo/"), 11); wp.back().router.add_route(StringRef::from_lit("/echo/"), 11);
wp.back().router.add_route(StringRef::from_lit("/echo/foxtrot"), 12); wp.back().router.add_route(StringRef::from_lit("/echo/foxtrot"), 12);
wp.emplace_back(StringRef::from_lit(".local"));
wcrouter.add_route(StringRef::from_lit("lacol."), 2);
wp.back().router.add_route(StringRef::from_lit("/"), 13);
CU_ASSERT(11 == match_downstream_addr_group( CU_ASSERT(11 == match_downstream_addr_group(
routerconf, StringRef::from_lit("git.nghttp2.org"), routerconf, StringRef::from_lit("git.nghttp2.org"),
StringRef::from_lit("/echo"), groups, 255, balloc)); StringRef::from_lit("/echo"), groups, 255, balloc));
@ -230,6 +238,10 @@ void test_shrpx_worker_match_downstream_addr_group(void) {
CU_ASSERT(0 == match_downstream_addr_group( CU_ASSERT(0 == match_downstream_addr_group(
routerconf, StringRef::from_lit("nghttp2.org"), routerconf, StringRef::from_lit("nghttp2.org"),
StringRef::from_lit("/echo"), groups, 255, balloc)); StringRef::from_lit("/echo"), groups, 255, balloc));
CU_ASSERT(13 == match_downstream_addr_group(
routerconf, StringRef::from_lit("test.local"),
StringRef{}, groups, 255, balloc));
} }
} // namespace shrpx } // namespace shrpx