aboutsummaryrefslogtreecommitdiffstats
path: root/include/routing.h
diff options
context:
space:
mode:
authoripknHama <ipknhama@gmail.com>2014-10-07 21:51:24 +0900
committeripknHama <ipknhama@gmail.com>2014-10-07 21:51:24 +0900
commita5fab23f70e6e33c633ba4b646a41d0851169ad1 (patch)
tree78a80f28adf2e145e061ee0a04e5ffc8fa915a1d /include/routing.h
parentd496f0f4b5a4f154ffdb89896d8de155a002c393 (diff)
downloadcrow-a5fab23f70e6e33c633ba4b646a41d0851169ad1.tar.gz
crow-a5fab23f70e6e33c633ba4b646a41d0851169ad1.zip
HTTP GET/POST method distinguish
Diffstat (limited to 'include/routing.h')
-rw-r--r--include/routing.h20
1 files changed, 17 insertions, 3 deletions
diff --git a/include/routing.h b/include/routing.h
index d814266..e62cbce 100644
--- a/include/routing.h
+++ b/include/routing.h
@@ -26,8 +26,13 @@ namespace crow
virtual void handle(const request&, response&, const routing_params&) = 0;
- protected:
+ uint32_t methods()
+ {
+ return methods_;
+ }
+ protected:
+ uint32_t methods_{1<<(int)HTTPMethod::GET};
};
template <typename ... Args>
@@ -147,6 +152,7 @@ namespace crow
self_t& methods(HTTPMethod method)
{
methods_ = 1<<(int)method;
+ return *this;
}
template <typename ... MethodArgs>
@@ -154,6 +160,7 @@ namespace crow
{
methods(args_method...);
methods_ |= 1<<(int)method;
+ return *this;
}
void validate()
@@ -257,7 +264,6 @@ namespace crow
std::string rule_;
std::string name_;
- uint32_t methods_{1<<(int)HTTPMethod::GET};
template <typename T, int Pos>
struct call_pair
@@ -641,7 +647,15 @@ public:
if (rule_index >= rules_.size())
throw std::runtime_error("Trie internal structure corrupted!");
- CROW_LOG_DEBUG << "Matched rule '" << ((TaggedRule<>*)rules_[rule_index].get())->rule_ << "'";
+ if ((rules_[rule_index]->methods() & (1<<(uint32_t)req.method)) == 0)
+ {
+ CROW_LOG_DEBUG << "Rule found but method mismatch: " << editedUrl << " with " << method_name(req.method) << "(" << (uint32_t)req.method << ") / " << rules_[rule_index]->methods();
+ res = response(404);
+ res.end();
+ return;
+ }
+
+ CROW_LOG_DEBUG << "Matched rule '" << ((TaggedRule<>*)rules_[rule_index].get())->rule_ << "' " << (uint32_t)req.method << " / " << rules_[rule_index]->methods();
rules_[rule_index]->handle(req, res, found.second);
}