diff --git a/examples/simple_example_test/main.cc b/examples/simple_example_test/main.cc index 74e4775b..7f9498e2 100644 --- a/examples/simple_example_test/main.cc +++ b/examples/simple_example_test/main.cc @@ -587,7 +587,7 @@ void doTest(const HttpClientPtr &client, /// Test static function req = HttpRequest::newHttpRequest(); req->setMethod(drogon::Get); - req->setPath("/api/v1/handle11/11/22/?p3=33"); + req->setPath("/api/v1/handle11/11/2 2/?p3=3 x"); req->setParameter("p4", "44"); client->sendRequest( req, [=](ReqResult result, const HttpResponsePtr &resp) { @@ -600,10 +600,10 @@ void doTest(const HttpClientPtr &client, "int p4\n 44") != std::string::npos && resp->getBody().find( - "string p2\n 22") != + "string p2\n 2 2") != std::string::npos && resp->getBody().find( - "string p3\n 33") != + "string p3\n 3 x") != std::string::npos) { outputGood(req, isHttps); diff --git a/lib/inc/drogon/HttpBinder.h b/lib/inc/drogon/HttpBinder.h index f2faf951..ec9708ff 100644 --- a/lib/inc/drogon/HttpBinder.h +++ b/lib/inc/drogon/HttpBinder.h @@ -68,7 +68,7 @@ class HttpBinderBase { public: virtual void handleHttpRequest( - std::list &pathParameter, + std::list &pathArguments, const HttpRequestPtr &req, std::function &&callback) = 0; virtual size_t paramCount() = 0; @@ -96,11 +96,11 @@ class HttpBinder : public HttpBinderBase public: typedef FUNCTION FunctionType; virtual void handleHttpRequest( - std::list &pathParameter, + std::list &pathArguments, const HttpRequestPtr &req, std::function &&callback) override { - run(pathParameter, req, std::move(callback)); + run(pathArguments, req, std::move(callback)); } virtual size_t paramCount() override { @@ -131,9 +131,24 @@ class HttpBinder : public HttpBinderBase static const size_t argument_count = traits::arity; std::string _handlerName; + template + void getHandlerArgumentValue(T &value, std::string &&p) + { + if (!p.empty()) + { + std::stringstream ss(std::move(p)); + ss >> value; + } + } + + void getHandlerArgumentValue(std::string &value, std::string &&p) + { + value = std::move(p); + } + template typename std::enable_if<(sizeof...(Values) < Boundary), void>::type run( - std::list &pathParameter, + std::list &pathArguments, const HttpRequestPtr &req, std::function &&callback, Values &&... values) @@ -147,18 +162,14 @@ class HttpBinder : public HttpBinderBase typedef typename std::remove_cv>::type>::type ValueType; ValueType value = ValueType(); - if (!pathParameter.empty()) + if (!pathArguments.empty()) { - std::string v = std::move(pathParameter.front()); - pathParameter.pop_front(); - if (!v.empty()) - { - std::stringstream ss(std::move(v)); - ss >> value; - } + std::string v = std::move(pathArguments.front()); + pathArguments.pop_front(); + getHandlerArgumentValue(value, std::move(v)); } - run(pathParameter, + run(pathArguments, req, std::move(callback), std::forward(values)..., @@ -166,7 +177,7 @@ class HttpBinder : public HttpBinderBase } template typename std::enable_if<(sizeof...(Values) == Boundary), void>::type run( - std::list &pathParameter, + std::list &pathArguments, const HttpRequestPtr &req, std::function &&callback, Values &&... values)