nghttpx: "*" must match at least one character

This commit is contained in:
Tatsuhiro Tsujikawa 2016-03-22 22:40:23 +09:00
parent 04145e22a2
commit 4bb88b35ec
4 changed files with 17 additions and 13 deletions

View File

@ -269,10 +269,11 @@ time:
We can use ``*`` in the left most position of host to achieve wildcard We can use ``*`` in the left most position of host to achieve wildcard
suffix match. If ``*`` is the left most character, then the remaining suffix match. If ``*`` is the left most character, then the remaining
string should match the request host suffix. For example, string should match the request host suffix. ``*`` must match at
``*.example.com`` matches ``www.example.com`` and ``dev.example.com``, least one character. For example, ``*.example.com`` matches
and does not match ``example.com`` and ``nghttp2.org``. The exact ``www.example.com`` and ``dev.example.com``, and does not match
match (without ``*``) always takes precedence over wildcard match. ``example.com`` and ``nghttp2.org``. The exact match (without ``*``)
always takes precedence over wildcard match.
One important thing you have to remember is that we have to specify One important thing you have to remember is that we have to specify
default routing pattern for so called "catch all" pattern. To write default routing pattern for so called "catch all" pattern. To write

View File

@ -1225,10 +1225,11 @@ Connections:
Host can include "*" in the left most position to Host can include "*" in the left most position to
indicate wildcard match (only suffix match is done). indicate wildcard match (only suffix match is done).
For example, host pattern "*www.nghttp2.org" matches The "*" must match at least one character. For example,
against "www.nghttp2.org" and "1www.ngttp2.org", but host pattern "*.nghttp2.org" matches against
does not match against "nghttp2.org". The exact hosts "www.nghttp2.org" and "git.ngttp2.org", but does not
match takes precedence over the wildcard hosts match. match against "nghttp2.org". The exact hosts match
takes precedence over the wildcard hosts match.
If <PATTERN> is omitted or empty string, "/" is used as If <PATTERN> is omitted or empty string, "/" is used as
pattern, which matches all request paths (catch-all pattern, which matches all request paths (catch-all

View File

@ -321,7 +321,9 @@ size_t match_downstream_addr_group_host(
for (auto it = std::begin(wildcard_patterns); for (auto it = std::begin(wildcard_patterns);
it != std::end(wildcard_patterns); ++it) { it != std::end(wildcard_patterns); ++it) {
if (!util::ends_with(std::begin(host), std::end(host), /* left most '*' must match at least one character */
if (host.size() <= (*it).host.size() ||
!util::ends_with(std::begin(host), std::end(host),
std::begin((*it).host), std::end((*it).host))) { std::begin((*it).host), std::end((*it).host))) {
continue; continue;
} }

View File

@ -188,7 +188,7 @@ 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);
CU_ASSERT(10 == match_downstream_addr_group( CU_ASSERT(11 == match_downstream_addr_group(
router, wp, StringRef::from_lit("git.nghttp2.org"), router, wp, StringRef::from_lit("git.nghttp2.org"),
StringRef::from_lit("/echo"), groups, 255)); StringRef::from_lit("/echo"), groups, 255));
@ -200,7 +200,7 @@ void test_shrpx_worker_match_downstream_addr_group(void) {
router, wp, StringRef::from_lit("it.nghttp2.org"), router, wp, StringRef::from_lit("it.nghttp2.org"),
StringRef::from_lit("/echo"), groups, 255)); StringRef::from_lit("/echo"), groups, 255));
CU_ASSERT(12 == match_downstream_addr_group( CU_ASSERT(255 == match_downstream_addr_group(
router, wp, StringRef::from_lit(".nghttp2.org"), router, wp, StringRef::from_lit(".nghttp2.org"),
StringRef::from_lit("/echo/foxtrot"), groups, 255)); StringRef::from_lit("/echo/foxtrot"), groups, 255));