Account for a reply that is finished before we can connect the signals

In a case where a connection is refused, then it is possible for it to
fail at the time that the QHttpNetworkReply is being created and
therefore after the connections have been made it would have already
emitted the signal to indicate it was finished with an error.

To account for this, then it checks if there is an error code set on
the reply and if there is then it will call the relevant slot right away.

Fixes: QTBUG-57799
Change-Id: I4e73e5c82092c09f825343d18db40b47c3cdb9ac
Reviewed-by: Timur Pocheptsov <timur.pocheptsov@qt.io>
This commit is contained in:
Andy Shaw 2020-02-07 15:00:55 +01:00
parent a82f9f1a1d
commit 5234c6c6a8
4 changed files with 15 additions and 0 deletions

View File

@ -1099,6 +1099,7 @@ void QHttpNetworkConnectionChannel::_q_error(QAbstractSocket::SocketError socket
if (reply) { if (reply) {
reply->d_func()->errorString = errorString; reply->d_func()->errorString = errorString;
reply->d_func()->httpErrorCode = errorCode;
emit reply->finishedWithError(errorCode, errorString); emit reply->finishedWithError(errorCode, errorString);
reply = 0; reply = 0;
if (protocolHandler) if (protocolHandler)

View File

@ -158,6 +158,11 @@ QString QHttpNetworkReply::errorString() const
return d_func()->errorString; return d_func()->errorString;
} }
QNetworkReply::NetworkError QHttpNetworkReply::errorCode() const
{
return d_func()->httpErrorCode;
}
QString QHttpNetworkReply::reasonPhrase() const QString QHttpNetworkReply::reasonPhrase() const
{ {
return d_func()->reasonPhrase; return d_func()->reasonPhrase;

View File

@ -115,6 +115,8 @@ public:
QString errorString() const; QString errorString() const;
void setErrorString(const QString &error); void setErrorString(const QString &error);
QNetworkReply::NetworkError errorCode() const;
QString reasonPhrase() const; QString reasonPhrase() const;
qint64 bytesAvailable() const; qint64 bytesAvailable() const;
@ -259,6 +261,7 @@ public:
qint64 removedContentLength; qint64 removedContentLength;
QPointer<QHttpNetworkConnection> connection; QPointer<QHttpNetworkConnection> connection;
QPointer<QHttpNetworkConnectionChannel> connectionChannel; QPointer<QHttpNetworkConnectionChannel> connectionChannel;
QNetworkReply::NetworkError httpErrorCode = QNetworkReply::NoError;
bool autoDecompress; bool autoDecompress;

View File

@ -428,6 +428,12 @@ void QHttpThreadDelegate::startRequest()
connect(httpReply, SIGNAL(cacheCredentials(QHttpNetworkRequest,QAuthenticator*)), connect(httpReply, SIGNAL(cacheCredentials(QHttpNetworkRequest,QAuthenticator*)),
this, SLOT(cacheCredentialsSlot(QHttpNetworkRequest,QAuthenticator*))); this, SLOT(cacheCredentialsSlot(QHttpNetworkRequest,QAuthenticator*)));
if (httpReply->errorCode() != QNetworkReply::NoError) {
if (synchronous)
synchronousFinishedWithErrorSlot(httpReply->errorCode(), httpReply->errorString());
else
finishedWithErrorSlot(httpReply->errorCode(), httpReply->errorString());
}
} }
// This gets called from the user thread or by the synchronous HTTP timeout timer // This gets called from the user thread or by the synchronous HTTP timeout timer