mirror of
https://github.com/QuasarApp/qthttpserver.git
synced 2025-05-05 22:39:33 +00:00
Allow using QHttpServerRequest/Responder at the same time
Fixes: QTBUG-77088 Change-Id: I2208cee290d086339aba705f959c57e0f6a73a87 Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
This commit is contained in:
parent
e35fdc4763
commit
43a04e17a1
src/httpserver
tests/auto
@ -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)
|
||||
|
@ -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 =
|
||||
|
@ -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")
|
||||
|
@ -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");
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user