odd methods wont match routes ever

feature/UrlUtils
Kenneth Barbour 2018-11-21 21:19:06 -05:00
parent a00fcae67e
commit 6ebd46210f
2 changed files with 24 additions and 6 deletions

View File

@ -23,7 +23,7 @@ const Route* RequestRouter::match(HttpRequest &request)
if (urlMatch) {
setRouteError(E_METHOD_NOT_ALLOWED);
return nullptr;
}
}
setRouteError(E_NOT_FOUND);
return nullptr;
@ -34,7 +34,7 @@ bool RequestRouter::urlMatches(const char * pattern, const char * url)
{
unsigned int u = 0;
unsigned int p = 0;
do {
if (pattern[p] == url[u] && url[u] == '\0')
return true;
@ -62,8 +62,8 @@ bool RequestRouter::urlMatches(const char * pattern, const char * url)
bool RequestRouter::methodMatches(uint8_t pattern, uint8_t method)
{
return (pattern & method) == method;
return method && (pattern & method) == method;
}
RequestRouter::~RequestRouter()
RequestRouter::~RequestRouter()
{}

View File

@ -87,7 +87,25 @@ TEST_CASE("Method not allowed", "[RequestRouter]")
HttpRequest request;
request.setMethod("PUT");
request.setUrl("/");
match = router.match(request);
CHECK(match == nullptr);
CHECK(router.getRouteError() == E_METHOD_NOT_ALLOWED);
CHECK(router.lastAllowedMethods() == GET);
}
TEST_CASE("Bad method", "[RequestRouter][BadMethod]")
{
Route routes[] = {
{ GET, "/" }
};
RequestRouter router(routes, 1);
const Route * match;
HttpRequest request;
request.setMethod("BAD");
request.setUrl("/");
match = router.match(request);
CHECK(match == nullptr);
CHECK(router.getRouteError() == E_METHOD_NOT_ALLOWED);
@ -115,5 +133,5 @@ TEST_CASE("Url Wildcards","[RequestRouter]")
CHECK(RequestRouter::urlMatches("/fs/#","/fs/foo/bar/baz") == true);
CHECK(RequestRouter::urlMatches("/*/*/*","/foo/bar/baz") == true);
CHECK(RequestRouter::urlMatches("/*/*/*","/foo/bar/baz/qux") == false);
}