diff options
author | Liang Qi <liang.qi@qt.io> | 2017-10-30 08:43:14 +0100 |
---|---|---|
committer | Liang Qi <liang.qi@qt.io> | 2017-10-30 08:54:05 +0100 |
commit | 17d51411132edef53e79dcbaf1046f06f79bed5d (patch) | |
tree | 38398d448b30313f91960c70a3a28cce91293da9 /src/network/access/qnetworkreplyhttpimpl.cpp | |
parent | ea0e868c4881944207e9b3a77011e05a505ff3b7 (diff) | |
parent | 9f0dda29d5d070f63b7f098139f01f07ec91ffdf (diff) |
Merge remote-tracking branch 'origin/5.9' into 5.10
Conflicts:
src/plugins/platforms/windows/qwindowswindow.cpp
tests/auto/widgets/kernel/qaction/tst_qaction.cpp
Change-Id: Ia017a825ed2ca2d53ac586f4ae48df6f65818d40
Diffstat (limited to 'src/network/access/qnetworkreplyhttpimpl.cpp')
-rw-r--r-- | src/network/access/qnetworkreplyhttpimpl.cpp | 82 |
1 files changed, 40 insertions, 42 deletions
diff --git a/src/network/access/qnetworkreplyhttpimpl.cpp b/src/network/access/qnetworkreplyhttpimpl.cpp index 46a2f2f208..382da0db5a 100644 --- a/src/network/access/qnetworkreplyhttpimpl.cpp +++ b/src/network/access/qnetworkreplyhttpimpl.cpp @@ -182,6 +182,7 @@ QNetworkReplyHttpImpl::QNetworkReplyHttpImpl(QNetworkAccessManager* const manage : QNetworkReply(*new QNetworkReplyHttpImplPrivate, manager) { Q_D(QNetworkReplyHttpImpl); + Q_ASSERT(manager); d->manager = manager; d->managerPrivate = manager->d_func(); d->request = request; @@ -395,9 +396,9 @@ bool QNetworkReplyHttpImpl::canReadLine () const void QNetworkReplyHttpImpl::ignoreSslErrors() { Q_D(QNetworkReplyHttpImpl); + Q_ASSERT(d->managerPrivate); - if (d->managerPrivate && d->managerPrivate->stsEnabled - && d->managerPrivate->stsCache.isKnownHost(url())) { + if (d->managerPrivate->stsEnabled && d->managerPrivate->stsCache.isKnownHost(url())) { // We cannot ignore any Security Transport-related errors for this host. return; } @@ -408,9 +409,9 @@ void QNetworkReplyHttpImpl::ignoreSslErrors() void QNetworkReplyHttpImpl::ignoreSslErrorsImplementation(const QList<QSslError> &errors) { Q_D(QNetworkReplyHttpImpl); + Q_ASSERT(d->managerPrivate); - if (d->managerPrivate && d->managerPrivate->stsEnabled - && d->managerPrivate->stsCache.isKnownHost(url())) { + if (d->managerPrivate->stsEnabled && d->managerPrivate->stsCache.isKnownHost(url())) { // We cannot ignore any Security Transport-related errors for this host. return; } @@ -1118,16 +1119,14 @@ QNetworkAccessManager::Operation QNetworkReplyHttpImplPrivate::getRedirectOperat // HTTP status code can be used to decide if we can redirect with a GET // operation or not. See http://www.ietf.org/rfc/rfc2616.txt [Sec 10.3] for // more details - Q_UNUSED(httpStatus); + + // We MUST keep using the verb that was used originally when being redirected with 307 or 308. + if (httpStatus == 307 || httpStatus == 308) + return currentOp; switch (currentOp) { case QNetworkAccessManager::HeadOperation: return QNetworkAccessManager::HeadOperation; - case QNetworkAccessManager::PostOperation: - // We MUST keep using POST when being redirected with 307 or 308. - if (statusCode == 307 || statusCode == 308) - return QNetworkAccessManager::PostOperation; - break; default: break; } @@ -1154,6 +1153,8 @@ QNetworkRequest QNetworkReplyHttpImplPrivate::createRedirectRequest(const QNetwo void QNetworkReplyHttpImplPrivate::onRedirected(const QUrl &redirectUrl, int httpStatus, int maxRedirectsRemaining) { Q_Q(QNetworkReplyHttpImpl); + Q_ASSERT(manager); + Q_ASSERT(managerPrivate); if (isFinished) return; @@ -1188,7 +1189,7 @@ void QNetworkReplyHttpImplPrivate::onRedirected(const QUrl &redirectUrl, int htt redirectRequest = createRedirectRequest(originalRequest, url, maxRedirectsRemaining); operation = getRedirectOperation(operation, httpStatus); - if (const QNetworkCookieJar *const cookieJar = (manager ? manager->cookieJar() : nullptr)) { + if (const QNetworkCookieJar *const cookieJar = manager->cookieJar()) { auto cookies = cookieJar->cookiesForUrl(url); if (!cookies.empty()) { redirectRequest.setHeader(QNetworkRequest::KnownHeaders::CookieHeader, @@ -1205,6 +1206,7 @@ void QNetworkReplyHttpImplPrivate::onRedirected(const QUrl &redirectUrl, int htt void QNetworkReplyHttpImplPrivate::followRedirect() { Q_Q(QNetworkReplyHttpImpl); + Q_ASSERT(managerPrivate); rawHeaders.clear(); cookedHeaders.clear(); @@ -1216,7 +1218,7 @@ void QNetworkReplyHttpImplPrivate::followRedirect() // If the original request didn't need a session (i.e. it was to localhost) // then we might not have a session open, to which to redirect, if the // new URL is remote. When this happens, we need to open the session now: - if (managerPrivate && isSessionNeeded(url)) { + if (isSessionNeeded(url)) { if (auto session = managerPrivate->getNetworkSession()) { if (session->state() != QNetworkSession::State::Connected || !session->isOpen()) { startWaitForSession(session); @@ -2052,9 +2054,7 @@ void QNetworkReplyHttpImplPrivate::_q_bufferOutgoingData() void QNetworkReplyHttpImplPrivate::_q_networkSessionConnected() { Q_Q(QNetworkReplyHttpImpl); - - if (!manager) - return; + Q_ASSERT(managerPrivate); QSharedPointer<QNetworkSession> session = managerPrivate->getNetworkSession(); if (!session) @@ -2184,28 +2184,27 @@ void QNetworkReplyHttpImplPrivate::finished() if (preMigrationDownloaded != Q_INT64_C(-1)) totalSize = totalSize.toLongLong() + preMigrationDownloaded; - if (manager) { #ifndef QT_NO_BEARERMANAGEMENT - QSharedPointer<QNetworkSession> session = managerPrivate->getNetworkSession(); - if (session && session->state() == QNetworkSession::Roaming && - state == Working && errorCode != QNetworkReply::OperationCanceledError) { - // only content with a known size will fail with a temporary network failure error - if (!totalSize.isNull()) { - if (bytesDownloaded != totalSize) { - if (migrateBackend()) { - // either we are migrating or the request is finished/aborted - if (state == Reconnecting || state == WaitingForSession) { - return; // exit early if we are migrating. - } - } else { - error(QNetworkReply::TemporaryNetworkFailureError, - QNetworkReply::tr("Temporary network failure.")); + Q_ASSERT(managerPrivate); + QSharedPointer<QNetworkSession> session = managerPrivate->getNetworkSession(); + if (session && session->state() == QNetworkSession::Roaming && + state == Working && errorCode != QNetworkReply::OperationCanceledError) { + // only content with a known size will fail with a temporary network failure error + if (!totalSize.isNull()) { + if (bytesDownloaded != totalSize) { + if (migrateBackend()) { + // either we are migrating or the request is finished/aborted + if (state == Reconnecting || state == WaitingForSession) { + return; // exit early if we are migrating. } + } else { + error(QNetworkReply::TemporaryNetworkFailureError, + QNetworkReply::tr("Temporary network failure.")); } } } -#endif } +#endif // if we don't know the total size of or we received everything save the cache if (totalSize.isNull() || totalSize == -1 || bytesDownloaded == totalSize) @@ -2263,17 +2262,16 @@ void QNetworkReplyHttpImplPrivate::_q_metaDataChanged() Q_Q(QNetworkReplyHttpImpl); // 1. do we have cookies? // 2. are we allowed to set them? - if (manager) { - const auto it = cookedHeaders.constFind(QNetworkRequest::SetCookieHeader); - if (it != cookedHeaders.cend() - && request.attribute(QNetworkRequest::CookieSaveControlAttribute, - QNetworkRequest::Automatic).toInt() == QNetworkRequest::Automatic) { - QNetworkCookieJar *jar = manager->cookieJar(); - if (jar) { - QList<QNetworkCookie> cookies = - qvariant_cast<QList<QNetworkCookie> >(it.value()); - jar->setCookiesFromUrl(cookies, url); - } + Q_ASSERT(manager); + const auto it = cookedHeaders.constFind(QNetworkRequest::SetCookieHeader); + if (it != cookedHeaders.cend() + && request.attribute(QNetworkRequest::CookieSaveControlAttribute, + QNetworkRequest::Automatic).toInt() == QNetworkRequest::Automatic) { + QNetworkCookieJar *jar = manager->cookieJar(); + if (jar) { + QList<QNetworkCookie> cookies = + qvariant_cast<QList<QNetworkCookie> >(it.value()); + jar->setCookiesFromUrl(cookies, url); } } emit q->metaDataChanged(); |