[Qt] Call QNetworkReply::readAll() only once
This commit is contained in:
@@ -80,9 +80,10 @@ void HTTPFileSource::Impl::onReplyFinished()
|
||||
return;
|
||||
}
|
||||
|
||||
QByteArray data = reply->readAll();
|
||||
QVector<HTTPRequest*>& requestsVector = it.value().second;
|
||||
for (auto req : requestsVector) {
|
||||
req->handleNetworkReply(reply);
|
||||
req->handleNetworkReply(reply, data);
|
||||
}
|
||||
|
||||
m_pending.erase(it);
|
||||
|
||||
@@ -52,7 +52,7 @@ QNetworkRequest HTTPRequest::networkRequest() const
|
||||
return req;
|
||||
}
|
||||
|
||||
void HTTPRequest::handleNetworkReply(QNetworkReply *reply)
|
||||
void HTTPRequest::handleNetworkReply(QNetworkReply *reply, const QByteArray& data)
|
||||
{
|
||||
m_handled = true;
|
||||
|
||||
@@ -98,11 +98,10 @@ void HTTPRequest::handleNetworkReply(QNetworkReply *reply)
|
||||
|
||||
switch(responseCode) {
|
||||
case 200: {
|
||||
QByteArray bytes = reply->readAll();
|
||||
if (bytes.isEmpty()) {
|
||||
if (data.isEmpty()) {
|
||||
response.data = std::make_shared<std::string>();
|
||||
} else {
|
||||
response.data = std::make_shared<std::string>(bytes.constData(), bytes.size());
|
||||
response.data = std::make_shared<std::string>(data.constData(), data.size());
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -20,7 +20,7 @@ public:
|
||||
QUrl requestUrl() const;
|
||||
QNetworkRequest networkRequest() const;
|
||||
|
||||
void handleNetworkReply(QNetworkReply *);
|
||||
void handleNetworkReply(QNetworkReply *, const QByteArray& data);
|
||||
|
||||
private:
|
||||
HTTPFileSource::Impl* m_context;
|
||||
|
||||
Reference in New Issue
Block a user