bmcweb: return 405 when a method is not supported
bmcweb previously took the crow approach to return codes, returning 200
for many things that didn't provide a VERB definition in its
declaration. This patch corrects bmcweb to return an appropriate error
code when the verb isn't supported.
Tested:
Ran test case here:
https://github.com/openbmc/bmcweb/issues/69
Observed 405 returned instead of 200.
Change-Id: I4c0fb5e68d6163ba6ff30faf1af403015888d475
Signed-off-by: Ed Tanous <ed.tanous@intel.com>
diff --git a/crow/include/crow/routing.h b/crow/include/crow/routing.h
index 7d7a1b6..32d31ef 100644
--- a/crow/include/crow/routing.h
+++ b/crow/include/crow/routing.h
@@ -1170,6 +1170,18 @@
if (!ruleIndex)
{
+ // Check to see if this url exists at any verb
+ for (const PerMethod& p : perMethods)
+ {
+ const std::pair<unsigned, RoutingParams>& found =
+ p.trie.find(req.url);
+ if (found.first > 0)
+ {
+ res.result(boost::beast::http::status::method_not_allowed);
+ res.end();
+ return;
+ }
+ }
BMCWEB_LOG_DEBUG << "Cannot match rules " << req.url;
res.result(boost::beast::http::status::not_found);
res.end();