| 83 | } |
| 84 | |
| 85 | void NetworkRequestHelper::AsyncHttpGet(const QString &url, std::function<void(const QByteArray &)> funcPtr) |
| 86 | { |
| 87 | QNetworkRequest request; |
| 88 | request.setUrl(url); |
| 89 | auto accessManagerPtr = new QNetworkAccessManager(); |
| 90 | setAccessManagerAttributes(request, *accessManagerPtr); |
| 91 | auto reply = accessManagerPtr->get(request); |
| 92 | QObject::connect(reply, &QNetworkReply::finished, [=]() { |
| 93 | { |
| 94 | #if QT_VERSION >= QT_VERSION_CHECK(5, 15, 0) |
| 95 | bool h2Used = reply->attribute(QNetworkRequest::Http2WasUsedAttribute).toBool(); |
| 96 | #else |
| 97 | bool h2Used = reply->attribute(QNetworkRequest::HTTP2WasUsedAttribute).toBool(); |
| 98 | #endif |
| 99 | if (h2Used) |
| 100 | DEBUG("HTTP/2 was used."); |
| 101 | |
| 102 | if (reply->error() != QNetworkReply::NoError) |
| 103 | LOG("Network error: " + QString(QMetaEnum::fromType<QNetworkReply::NetworkError>().key(reply->error()))); |
| 104 | |
| 105 | funcPtr(reply->readAll()); |
| 106 | accessManagerPtr->deleteLater(); |
| 107 | } |
| 108 | }); |
| 109 | } |
| 110 | |
| 111 | } // namespace Qv2ray::common::network |
no test coverage detected