// TODO: Implement cache and use a tree to improve speed bool HttpServerRequestRouter::handleRequest(HttpServerRequest &request, HttpServerResponse &response) { const QString path{request.url().path()}; for (const auto &mapping: priv->mappings) { QRegularExpressionMatch match{mapping.path.match(path)}; if (match.hasMatch()) { if (mapping.method.size() && request.method() != mapping.method) continue; QStringList args{match.capturedTexts().mid(1)}; QVariant backup{request.customData()}; if (args.size()) { QVariantMap options{backup.toMap()}; options["args"] = options["args"].toStringList() + args; request.setCustomData(options); } if (mapping.handler(request, response)) return true; if (args.size()) request.setCustomData(backup); } } return false; }
bool Handler::handleRequest(HttpServerRequest &request, HttpServerResponse &response) { // ... QStringList args = request.customData().toMap()["args"].toStringList(); // ... }