Add simple "any" route to catch any method

This commit is contained in:
Alex Hultman
2019-01-22 13:55:28 +01:00
parent 6d469cd8ba
commit f4065b4e3b
3 changed files with 17 additions and 5 deletions
+3 -2
View File
@@ -268,8 +268,9 @@ public:
return std::move(*this);
}
TemplatedApp &&unhandled(std::function<void(HttpResponse<SSL> *, HttpRequest *)> handler) {
httpContext->onUnhandled(handler);
/* This one catches any method */
TemplatedApp &&any(std::string pattern, std::function<void(HttpResponse<SSL> *, HttpRequest *)> handler) {
httpContext->onHttp("*", pattern, handler);
return std::move(*this);
}
+10 -2
View File
@@ -154,9 +154,17 @@ private:
}
if (parent != &tree) {
return matchUrlSegment(parent, 0);
int handler = matchUrlSegment(parent, 0);
/* We failed to match */
if (!handler && method.length() > 1) {
return lookupNew("*", url);
}
return handler;
} else {
return 0;
/* Unhandled, check if we have any "all" route for this url */
return method.length() == 1 ? 0 : lookupNew("*", url);
}
}