summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/httpserver/qhttpserver.h24
-rw-r--r--src/httpserver/qhttpserverrouterviewtraits.h4
-rw-r--r--tests/auto/qhttpserver/tst_qhttpserver.cpp27
-rw-r--r--tests/auto/qhttpserverrouter/tst_qhttpserverrouter.cpp12
4 files changed, 58 insertions, 9 deletions
diff --git a/src/httpserver/qhttpserver.h b/src/httpserver/qhttpserver.h
index d5ebdcb..80bad2c 100644
--- a/src/httpserver/qhttpserver.h
+++ b/src/httpserver/qhttpserver.h
@@ -112,7 +112,16 @@ private:
}
template<typename ViewTraits, typename T>
- typename std::enable_if<ViewTraits::Arguments::Last::IsRequest::Value, void>::type
+ typename std::enable_if<ViewTraits::Arguments::Last::IsRequest::Value &&
+ ViewTraits::Arguments::PlaceholdersCount == 2, void>::type
+ responseImpl(T &boundViewHandler, const QHttpServerRequest &request, QTcpSocket *socket)
+ {
+ boundViewHandler(makeResponder(request, socket), request);
+ }
+
+ template<typename ViewTraits, typename T>
+ typename std::enable_if<ViewTraits::Arguments::Last::IsRequest::Value &&
+ ViewTraits::Arguments::PlaceholdersCount == 1, void>::type
responseImpl(T &boundViewHandler, const QHttpServerRequest &request, QTcpSocket *socket)
{
const QHttpServerResponse response(boundViewHandler(request));
@@ -120,7 +129,18 @@ private:
}
template<typename ViewTraits, typename T>
- typename std::enable_if<ViewTraits::Arguments::Last::IsResponder::Value, void>::type
+ typename std::enable_if<ViewTraits::Arguments::Last::IsResponder::Value &&
+ ViewTraits::Arguments::PlaceholdersCount == 2, void>::type
+ responseImpl(T &boundViewHandler,
+ const QHttpServerRequest &request,
+ QTcpSocket *socket)
+ {
+ boundViewHandler(request, makeResponder(request, socket));
+ }
+
+ template<typename ViewTraits, typename T>
+ typename std::enable_if<ViewTraits::Arguments::Last::IsResponder::Value &&
+ ViewTraits::Arguments::PlaceholdersCount == 1, void>::type
responseImpl(T &boundViewHandler,
const QHttpServerRequest &request,
QTcpSocket *socket)
diff --git a/src/httpserver/qhttpserverrouterviewtraits.h b/src/httpserver/qhttpserverrouterviewtraits.h
index b4ce4fb..377811c 100644
--- a/src/httpserver/qhttpserverrouterviewtraits.h
+++ b/src/httpserver/qhttpserverrouterviewtraits.h
@@ -169,8 +169,10 @@ struct ViewTraitsHelper {
static constexpr bool TypeMatched = isType<CleanTypeT, true>();
static constexpr bool TypeCVRefMatched = isType<T>();
+
static constexpr bool ValidPosition =
- (I == FunctionTraits::ArgumentIndexMax);
+ (I == FunctionTraits::ArgumentIndexMax ||
+ I == FunctionTraits::ArgumentIndexMax - 1);
static constexpr bool ValidAll = TypeCVRefMatched && ValidPosition;
static constexpr bool assertCondition =
diff --git a/tests/auto/qhttpserver/tst_qhttpserver.cpp b/tests/auto/qhttpserver/tst_qhttpserver.cpp
index ef5290e..ec4fad3 100644
--- a/tests/auto/qhttpserver/tst_qhttpserver.cpp
+++ b/tests/auto/qhttpserver/tst_qhttpserver.cpp
@@ -149,6 +149,19 @@ struct CustomArg {
void tst_QHttpServer::initTestCase()
{
+
+ httpserver.route("/req-and-resp", [] (QHttpServerResponder &&resp,
+ const QHttpServerRequest &req) {
+ resp.write(req.body(),
+ QHttpServerLiterals::contentTypeTextHtml());
+ });
+
+ httpserver.route("/resp-and-req", [] (const QHttpServerRequest &req,
+ QHttpServerResponder &&resp) {
+ resp.write(req.body(),
+ QHttpServerLiterals::contentTypeTextHtml());
+ });
+
httpserver.route("/test", [] (QHttpServerResponder &&responder) {
responder.write("test msg",
QHttpServerLiterals::contentTypeTextHtml());
@@ -655,6 +668,20 @@ void tst_QHttpServer::routePost_data()
<< body
<< body;
+ QTest::addRow("req-and-resp")
+ << urlBase.arg("/req-and-resp")
+ << 200
+ << "text/html"
+ << "test"
+ << "test";
+
+ QTest::addRow("resp-and-req")
+ << urlBase.arg("/resp-and-req")
+ << 200
+ << "text/html"
+ << "test"
+ << "test";
+
#if QT_CONFIG(ssl)
QTest::addRow("post-and-get, post, ssl")
diff --git a/tests/auto/qhttpserverrouter/tst_qhttpserverrouter.cpp b/tests/auto/qhttpserverrouter/tst_qhttpserverrouter.cpp
index 4f70018..5536408 100644
--- a/tests/auto/qhttpserverrouter/tst_qhttpserverrouter.cpp
+++ b/tests/auto/qhttpserverrouter/tst_qhttpserverrouter.cpp
@@ -486,21 +486,21 @@ void tst_QHttpServerRouter::viewHandlerLastTwoSpecials()
using Arg0 = typename Args::template Arg<0>;
static_assert(Arg0::IsRequest::Value,
"viewTwoSpecialArgs: Args::Arg0::IsRequest::Value");
- static_assert(Arg0::IsRequest::Valid == 0,
- "viewTwoSpecialArgs: Args::Arg0::IsRequest::Valid == 0");
+ static_assert(Arg0::IsRequest::Valid,
+ "viewTwoSpecialArgs: Args::Arg0::IsRequest::Valid");
static_assert(Arg0::IsResponder::Value == 0,
"viewTwoSpecialArgs: Args::Arg0::IsResponder::Value == 0");
static_assert(Arg0::IsResponder::Valid == 0,
"viewTwoSpecialArgs: Args::Arg0::IsResponder::Valid == 0");
static_assert(Arg0::IsSpecial::Value,
"viewTwoSpecialArgs: Args::Arg0::IsSpecial::Value");
- static_assert(Arg0::IsSpecial::Valid == 0,
- "viewTwoSpecialArgs: Args::Arg0::IsSpecial::Valid == 0");
+ static_assert(Arg0::IsSpecial::Valid,
+ "viewTwoSpecialArgs: Args::Arg0::IsSpecial::Valid");
static_assert(Arg0::IsSimple::Value == 0,
"viewTwoSpecialArgs: Args::Arg0::IsSimple::Value == 0");
static_assert(Arg0::IsSimple::Valid == 0,
"viewTwoSpecialArgs: Args::Arg0::IsSimple::Valid == 0");
- static_assert(Arg0::Valid == 0,
+ static_assert(Arg0::Valid,
"viewTwoSpecialArgs: Args::Arg0::Valid");
// StaticAssert is disabled in tests
static_assert(Arg0::StaticAssert,
@@ -532,7 +532,7 @@ void tst_QHttpServerRouter::viewHandlerLastTwoSpecials()
static_assert(Arg1::isType<QHttpServerResponder &&>(),
"viewTwoSpecialArgs: Args::Arg1::isType<QHttpServerResponder &&>()");
- static_assert(Args::Valid == 0, "viewTwoSpecialArgs: Args::Valid");
+ static_assert(Args::Valid, "viewTwoSpecialArgs: Args::Valid");
// StaticAssert is disabled in tests
static_assert(Args::StaticAssert, "viewTwoSpecialArgs: Args::StaticAssert");
}