mirror of
https://github.com/tumic0/GPXSee.git
synced 2024-11-24 11:45:53 +01:00
Use QNetworkRequest::setTransferTimeout where available
This commit is contained in:
parent
aed09a0e6a
commit
bcfd51276f
@ -56,6 +56,7 @@ Authorization::Authorization(const QString &username, const QString &password)
|
|||||||
_header = HTTPHeader("Authorization", "Basic " + data);
|
_header = HTTPHeader("Authorization", "Basic " + data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if QT_VERSION < QT_VERSION_CHECK(5, 15, 0)
|
||||||
NetworkTimeout::NetworkTimeout(int timeout, QNetworkReply *reply)
|
NetworkTimeout::NetworkTimeout(int timeout, QNetworkReply *reply)
|
||||||
: QObject(reply), _timeout(timeout)
|
: QObject(reply), _timeout(timeout)
|
||||||
{
|
{
|
||||||
@ -77,6 +78,7 @@ void NetworkTimeout::timerEvent(QTimerEvent *ev)
|
|||||||
reply->abort();
|
reply->abort();
|
||||||
_timer.stop();
|
_timer.stop();
|
||||||
}
|
}
|
||||||
|
#endif // QT 5.15
|
||||||
|
|
||||||
|
|
||||||
QNetworkAccessManager *Downloader::_manager = 0;
|
QNetworkAccessManager *Downloader::_manager = 0;
|
||||||
@ -104,11 +106,15 @@ bool Downloader::doDownload(const Download &dl, const QList<HTTPHeader> &headers
|
|||||||
request.setAttribute(ATTR_REDIRECT_POLICY,
|
request.setAttribute(ATTR_REDIRECT_POLICY,
|
||||||
QNetworkRequest::NoLessSafeRedirectPolicy);
|
QNetworkRequest::NoLessSafeRedirectPolicy);
|
||||||
request.setAttribute(ATTR_HTTP2_ALLOWED, QVariant(_http2));
|
request.setAttribute(ATTR_HTTP2_ALLOWED, QVariant(_http2));
|
||||||
|
#if QT_VERSION >= QT_VERSION_CHECK(5, 15, 0)
|
||||||
|
request.setTransferTimeout(_timeout * 1000);
|
||||||
|
#endif // QT 5.15
|
||||||
|
|
||||||
for (int i = 0; i < headers.size(); i++) {
|
for (int i = 0; i < headers.size(); i++) {
|
||||||
const HTTPHeader &hdr = headers.at(i);
|
const HTTPHeader &hdr = headers.at(i);
|
||||||
request.setRawHeader(hdr.key(), hdr.value());
|
request.setRawHeader(hdr.key(), hdr.value());
|
||||||
if (hdr.key() == "User-Agent")
|
// QByteArray::compare() not available in Qt < 5.12
|
||||||
|
if (!QString(hdr.key()).compare("User-Agent", Qt::CaseInsensitive))
|
||||||
userAgent = true;
|
userAgent = true;
|
||||||
}
|
}
|
||||||
if (!userAgent)
|
if (!userAgent)
|
||||||
@ -128,9 +134,9 @@ bool Downloader::doDownload(const Download &dl, const QList<HTTPHeader> &headers
|
|||||||
_currentDownloads.insert(url, file);
|
_currentDownloads.insert(url, file);
|
||||||
|
|
||||||
if (reply->isRunning()) {
|
if (reply->isRunning()) {
|
||||||
/* Starting with Qt 5.15 this can be replaced by
|
#if QT_VERSION < QT_VERSION_CHECK(5, 15, 0)
|
||||||
QNetworkRequest::setTransferTimeout() */
|
|
||||||
new NetworkTimeout(_timeout, reply);
|
new NetworkTimeout(_timeout, reply);
|
||||||
|
#endif // QT 5.15
|
||||||
connect(reply, &QIODevice::readyRead, this, &Downloader::emitReadReady);
|
connect(reply, &QIODevice::readyRead, this, &Downloader::emitReadReady);
|
||||||
connect(reply, &QNetworkReply::finished, this, &Downloader::emitFinished);
|
connect(reply, &QNetworkReply::finished, this, &Downloader::emitFinished);
|
||||||
} else {
|
} else {
|
||||||
|
@ -39,6 +39,7 @@ private:
|
|||||||
HTTPHeader _header;
|
HTTPHeader _header;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#if QT_VERSION < QT_VERSION_CHECK(5, 15, 0)
|
||||||
class NetworkTimeout : public QObject
|
class NetworkTimeout : public QObject
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
@ -55,6 +56,7 @@ private:
|
|||||||
QBasicTimer _timer;
|
QBasicTimer _timer;
|
||||||
int _timeout;
|
int _timeout;
|
||||||
};
|
};
|
||||||
|
#endif // QT 5.15
|
||||||
|
|
||||||
class Downloader : public QObject
|
class Downloader : public QObject
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user