const QString USER_AGENT = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_2) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.95 Safari/537.11";
-NetworkReply::NetworkReply(QNetworkReply *networkReply) : QObject(networkReply) {
- this->networkReply = networkReply;
+NetworkReply::NetworkReply(QNetworkReply *networkReply) :
+ QObject(networkReply),
+ networkReply(networkReply),
+ retryCount(0) {
+
setupReply();
readTimeoutTimer = new QTimer(this);
setupReply();
readTimeoutTimer->start();
return;
- } else qWarning("Redirection not supported");
+ } else qWarning() << "Redirection not supported" << networkReply->url().toEncoded();
}
if (receivers(SIGNAL(data(QByteArray))) > 0)
return;
}
+ if (retryCount > 3) {
+ emit error(networkReply);
+ return;
+ }
QNetworkReply *retryReply = The::http()->request(networkReply->url(), networkReply->operation());
setParent(retryReply);
networkReply = retryReply;
setupReply();
+ retryCount++;
+ readTimeoutTimer->start();
}
/* --- NetworkAccess --- */
public:
NetworkReply(QNetworkReply* networkReply);
-
-public slots:
- void finished();
- void requestError(QNetworkReply::NetworkError);
- void downloadProgress(qint64 bytesReceived, qint64 bytesTotal);
- void readTimeout();
+ QNetworkReply* getNetworkReply() { return networkReply; }
signals:
void data(QByteArray);
void error(QNetworkReply*);
void finished(QNetworkReply*);
+private slots:
+ void finished();
+ void requestError(QNetworkReply::NetworkError);
+ void downloadProgress(qint64 bytesReceived, qint64 bytesTotal);
+ void readTimeout();
+
private:
void setupReply();
QNetworkReply *networkReply;
QTimer *readTimeoutTimer;
+ int retryCount;
};