diff options
author | Lars Knoll <lars.knoll@nokia.com> | 2012-04-17 12:58:41 +0200 |
---|---|---|
committer | Lars Knoll <lars.knoll@nokia.com> | 2012-04-17 12:58:52 +0200 |
commit | 64255ef6502b1144f7b0aa4b2bf62803e0d4788b (patch) | |
tree | 29bf116bfda2ccf61057115690d14f85cc9b085b /src/network/access/qnetworkreplyhttpimpl.cpp | |
parent | 4a9fb41a7947d0bb7a47a9625603a436df288b24 (diff) | |
parent | 7e0beba891cb963a1d535bd45b0be78b43b8d07f (diff) |
Merge remote-tracking branch 'origin/api_changes'
Change-Id: I964b0a6f5c38351fdfafb8a2a128a349ff8c89d1
Diffstat (limited to 'src/network/access/qnetworkreplyhttpimpl.cpp')
-rw-r--r-- | src/network/access/qnetworkreplyhttpimpl.cpp | 41 |
1 files changed, 35 insertions, 6 deletions
diff --git a/src/network/access/qnetworkreplyhttpimpl.cpp b/src/network/access/qnetworkreplyhttpimpl.cpp index 7977704e38..cac8098057 100644 --- a/src/network/access/qnetworkreplyhttpimpl.cpp +++ b/src/network/access/qnetworkreplyhttpimpl.cpp @@ -1041,7 +1041,7 @@ void QNetworkReplyHttpImplPrivate::checkForRedirect(const int statusCode) // The response to a 303 MUST NOT be cached, while the response to // all of the others is cacheable if the headers indicate it to be QByteArray header = q->rawHeader("location"); - QUrl url = QUrl::fromEncoded(header); + QUrl url = QUrl(QString::fromUtf8(header)); if (!url.isValid()) url = QUrl(QLatin1String(header)); // FIXME? @@ -1531,6 +1531,8 @@ bool QNetworkReplyHttpImplPrivate::start() void QNetworkReplyHttpImplPrivate::_q_startOperation() { + Q_Q(QNetworkReplyHttpImpl); + // ensure this function is only being called once if (state == Working) { qDebug("QNetworkReplyImpl::_q_startOperation was called more than once"); @@ -1538,6 +1540,19 @@ void QNetworkReplyHttpImplPrivate::_q_startOperation() } state = Working; +#ifndef QT_NO_BEARERMANAGEMENT + // Do not start background requests if they are not allowed by session policy + QSharedPointer<QNetworkSession> session(manager->d_func()->networkSession); + QVariant isBackground = request.attribute(QNetworkRequest::BackgroundRequestAttribute, QVariant::fromValue(false)); + if (isBackground.toBool() && session && session->usagePolicies().testFlag(QNetworkSession::NoBackgroundTrafficPolicy)) { + QMetaObject::invokeMethod(q, "_q_error", synchronous ? Qt::DirectConnection : Qt::QueuedConnection, + Q_ARG(QNetworkReply::NetworkError, QNetworkReply::BackgroundRequestNotAllowedError), + Q_ARG(QString, QCoreApplication::translate("QNetworkReply", "Background request not allowed."))); + QMetaObject::invokeMethod(q, "_q_finished", synchronous ? Qt::DirectConnection : Qt::QueuedConnection); + return; + } +#endif + if (!start()) { #ifndef QT_NO_BEARERMANAGEMENT // backend failed to start because the session state is not Connected. @@ -1547,8 +1562,6 @@ void QNetworkReplyHttpImplPrivate::_q_startOperation() QNetworkSession *session = managerPrivate->networkSession.data(); if (session) { - Q_Q(QNetworkReplyHttpImpl); - QObject::connect(session, SIGNAL(error(QNetworkSession::SessionError)), q, SLOT(_q_networkSessionFailed())); @@ -1556,9 +1569,20 @@ void QNetworkReplyHttpImplPrivate::_q_startOperation() session->open(); } else { qWarning("Backend is waiting for QNetworkSession to connect, but there is none!"); + QMetaObject::invokeMethod(q, "_q_error", synchronous ? Qt::DirectConnection : Qt::QueuedConnection, + Q_ARG(QNetworkReply::NetworkError, QNetworkReply::NetworkSessionFailedError), + Q_ARG(QString, QCoreApplication::translate("QNetworkReply", "Network session error."))); + QMetaObject::invokeMethod(q, "_q_finished", synchronous ? Qt::DirectConnection : Qt::QueuedConnection); + return; } -#endif +#else + qWarning("Backend start failed"); + QMetaObject::invokeMethod(q, "_q_error", synchronous ? Qt::DirectConnection : Qt::QueuedConnection, + Q_ARG(QNetworkReply::NetworkError, QNetworkReply::UnknownNetworkError), + Q_ARG(QString, QCoreApplication::translate("QNetworkReply", "backend start error."))); + QMetaObject::invokeMethod(q, "_q_finished", synchronous ? Qt::DirectConnection : Qt::QueuedConnection); return; +#endif } if (synchronous) { @@ -1728,8 +1752,13 @@ void QNetworkReplyHttpImplPrivate::_q_networkSessionFailed() // Abort waiting and working replies. if (state == WaitingForSession || state == Working) { state = Working; - error(QNetworkReplyImpl::UnknownNetworkError, - QCoreApplication::translate("QNetworkReply", "Network session error.")); + QSharedPointer<QNetworkSession> session(manager->d_func()->networkSession); + QString errorStr; + if (session) + errorStr = session->errorString(); + else + errorStr = QCoreApplication::translate("QNetworkReply", "Network session error."); + error(QNetworkReplyImpl::NetworkSessionFailedError, errorStr); finished(); } } |