diff options
author | Sergio Ahumada <sergio.ahumada@digia.com> | 2013-03-20 23:30:31 +0100 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2013-03-20 23:30:31 +0100 |
commit | e5a11fbb3251a98fafd6bebf0b6fc366acb19088 (patch) | |
tree | 8e1bd6704205307e0a23484221ea1bb67a9f411e /src/network/access | |
parent | 0646d1131b4bc65cdd9af29f4ce00fdd2398a3df (diff) | |
parent | 76c0be34cd4ff4564693162fa7528463e23ce9d8 (diff) |
Merge "Merge branch 'dev' into stable" into refs/staging/stable
Diffstat (limited to 'src/network/access')
28 files changed, 195 insertions, 65 deletions
diff --git a/src/network/access/qabstractnetworkcache.h b/src/network/access/qabstractnetworkcache.h index 6a4d36ced3..b9a086f047 100644 --- a/src/network/access/qabstractnetworkcache.h +++ b/src/network/access/qabstractnetworkcache.h @@ -47,8 +47,6 @@ #include <QtCore/qpair.h> #include <QtNetwork/qnetworkrequest.h> -QT_BEGIN_HEADER - QT_BEGIN_NAMESPACE @@ -141,6 +139,4 @@ private: QT_END_NAMESPACE -QT_END_HEADER - #endif diff --git a/src/network/access/qftp_p.h b/src/network/access/qftp_p.h index d87a743036..ee5d124650 100644 --- a/src/network/access/qftp_p.h +++ b/src/network/access/qftp_p.h @@ -57,8 +57,6 @@ #include <private/qurlinfo_p.h> #include <QtCore/qobject.h> -QT_BEGIN_HEADER - QT_BEGIN_NAMESPACE @@ -176,6 +174,4 @@ private: QT_END_NAMESPACE -QT_END_HEADER - #endif // QFTP_H diff --git a/src/network/access/qhttpmultipart.h b/src/network/access/qhttpmultipart.h index 9913b64de6..71075ad2f3 100644 --- a/src/network/access/qhttpmultipart.h +++ b/src/network/access/qhttpmultipart.h @@ -47,8 +47,6 @@ #include <QtCore/QIODevice> #include <QtNetwork/QNetworkRequest> -QT_BEGIN_HEADER - QT_BEGIN_NAMESPACE @@ -119,6 +117,4 @@ private: QT_END_NAMESPACE -QT_END_HEADER - #endif // QHTTPMULTIPART_H diff --git a/src/network/access/qhttpnetworkconnection.cpp b/src/network/access/qhttpnetworkconnection.cpp index eec5cfa96d..a279990f4c 100644 --- a/src/network/access/qhttpnetworkconnection.cpp +++ b/src/network/access/qhttpnetworkconnection.cpp @@ -923,7 +923,7 @@ void QHttpNetworkConnectionPrivate::_q_startNextRequest() fillPipeline(channels[i].socket); // If there is not already any connected channels we need to connect a new one. - // We do not pair the channel with the request until we know if it is + // We do not pair the channel with the request until we know if it is // connected or not. This is to reuse connected channels before we connect new once. int queuedRequest = highPriorityQueue.count() + lowPriorityQueue.count(); for (int i = 0; i < channelCount; ++i) { @@ -1224,6 +1224,18 @@ void QHttpNetworkConnection::setSslConfiguration(const QSslConfiguration &config d->channels[i].setSslConfiguration(config); } +QSharedPointer<QSslContext> QHttpNetworkConnection::sslContext() +{ + Q_D(QHttpNetworkConnection); + return d->sslContext; +} + +void QHttpNetworkConnection::setSslContext(QSharedPointer<QSslContext> context) +{ + Q_D(QHttpNetworkConnection); + d->sslContext = context; +} + void QHttpNetworkConnection::ignoreSslErrors(int channel) { Q_D(QHttpNetworkConnection); diff --git a/src/network/access/qhttpnetworkconnection_p.h b/src/network/access/qhttpnetworkconnection_p.h index 57d40bfcf2..956499ddab 100644 --- a/src/network/access/qhttpnetworkconnection_p.h +++ b/src/network/access/qhttpnetworkconnection_p.h @@ -62,6 +62,7 @@ #include <qnetworkproxy.h> #include <qbuffer.h> #include <qtimer.h> +#include <qsharedpointer.h> #include <private/qhttpnetworkheader_p.h> #include <private/qhttpnetworkrequest_p.h> @@ -72,6 +73,8 @@ #ifndef QT_NO_HTTP #ifndef QT_NO_SSL +# include <private/qsslcontext_p.h> +# include <private/qsslsocket_p.h> # include <QtNetwork/qsslsocket.h> # include <QtNetwork/qsslerror.h> #else @@ -124,6 +127,8 @@ public: void setSslConfiguration(const QSslConfiguration &config); void ignoreSslErrors(int channel = -1); void ignoreSslErrors(const QList<QSslError> &errors, int channel = -1); + QSharedPointer<QSslContext> sslContext(); + void setSslContext(QSharedPointer<QSslContext> context); #endif private: @@ -234,6 +239,10 @@ public: QList<HttpMessagePair> highPriorityQueue; QList<HttpMessagePair> lowPriorityQueue; +#ifndef QT_NO_SSL + QSharedPointer<QSslContext> sslContext; +#endif + #ifndef QT_NO_BEARERMANAGEMENT QSharedPointer<QNetworkSession> networkSession; #endif diff --git a/src/network/access/qhttpnetworkconnectionchannel.cpp b/src/network/access/qhttpnetworkconnectionchannel.cpp index 38723a7032..4b8fe8aca7 100644 --- a/src/network/access/qhttpnetworkconnectionchannel.cpp +++ b/src/network/access/qhttpnetworkconnectionchannel.cpp @@ -622,6 +622,13 @@ bool QHttpNetworkConnectionChannel::ensureConnection() if (ssl) { #ifndef QT_NO_SSL QSslSocket *sslSocket = qobject_cast<QSslSocket*>(socket); + + // check whether we can re-use an existing SSL session + // (meaning another socket in this connection has already + // performed a full handshake) + if (!connection->sslContext().isNull()) + QSslSocketPrivate::checkSettingSslContext(sslSocket, connection->sslContext()); + sslSocket->connectToHostEncrypted(connectHost, connectPort, QIODevice::ReadWrite, networkLayerPreference); if (ignoreAllSslErrors) sslSocket->ignoreSslErrors(); @@ -1065,7 +1072,17 @@ void QHttpNetworkConnectionChannel::_q_connected() // ### FIXME: if the server closes the connection unexpectedly, we shouldn't send the same broken request again! //channels[i].reconnectAttempts = 2; - if (!pendingEncrypt) { + if (pendingEncrypt) { +#ifndef QT_NO_SSL + if (connection->sslContext().isNull()) { + // this socket is making the 1st handshake for this connection, + // we need to set the SSL context so new sockets can reuse it + QSharedPointer<QSslContext> socketSslContext = QSslSocketPrivate::sslContext(static_cast<QSslSocket*>(socket)); + if (!socketSslContext.isNull()) + connection->setSslContext(socketSslContext); + } +#endif + } else { state = QHttpNetworkConnectionChannel::IdleState; if (!reply) connection->d_func()->dequeueRequest(socket); @@ -1208,6 +1225,8 @@ void QHttpNetworkConnectionChannel::_q_encrypted() if (!reply) connection->d_func()->dequeueRequest(socket); if (reply) + emit reply->encrypted(); + if (reply) sendRequest(); } diff --git a/src/network/access/qhttpnetworkconnectionchannel_p.h b/src/network/access/qhttpnetworkconnectionchannel_p.h index 3577d76df5..c8138b5453 100644 --- a/src/network/access/qhttpnetworkconnectionchannel_p.h +++ b/src/network/access/qhttpnetworkconnectionchannel_p.h @@ -146,7 +146,7 @@ public: QHttpNetworkConnectionChannel(); QAbstractSocket::NetworkLayerProtocol networkLayerPreference; - + void setConnection(QHttpNetworkConnection *c); QPointer<QHttpNetworkConnection> connection; diff --git a/src/network/access/qhttpnetworkreply_p.h b/src/network/access/qhttpnetworkreply_p.h index e849c66659..7aea9f14ec 100644 --- a/src/network/access/qhttpnetworkreply_p.h +++ b/src/network/access/qhttpnetworkreply_p.h @@ -142,6 +142,7 @@ public: void ignoreSslErrors(const QList<QSslError> &errors); Q_SIGNALS: + void encrypted(); void sslErrors(const QList<QSslError> &errors); #endif diff --git a/src/network/access/qhttpthreaddelegate.cpp b/src/network/access/qhttpthreaddelegate.cpp index 117265dbfb..a2cee48b22 100644 --- a/src/network/access/qhttpthreaddelegate.cpp +++ b/src/network/access/qhttpthreaddelegate.cpp @@ -315,6 +315,7 @@ void QHttpThreadDelegate::startRequest() connect(httpReply,SIGNAL(readyRead()), this, SLOT(readyReadSlot())); connect(httpReply,SIGNAL(dataReadProgress(qint64,qint64)), this, SLOT(dataReadProgressSlot(qint64,qint64))); #ifndef QT_NO_SSL + connect(httpReply,SIGNAL(encrypted()), this, SLOT(encryptedSlot())); connect(httpReply,SIGNAL(sslErrors(QList<QSslError>)), this, SLOT(sslErrorsSlot(QList<QSslError>))); #endif @@ -589,6 +590,14 @@ void QHttpThreadDelegate::cacheCredentialsSlot(const QHttpNetworkRequest &reques #ifndef QT_NO_SSL +void QHttpThreadDelegate::encryptedSlot() +{ + if (!httpReply) + return; + + emit encrypted(); +} + void QHttpThreadDelegate::sslErrorsSlot(const QList<QSslError> &errors) { if (!httpReply) diff --git a/src/network/access/qhttpthreaddelegate_p.h b/src/network/access/qhttpthreaddelegate_p.h index 86192c77cc..d9ef1a0a55 100644 --- a/src/network/access/qhttpthreaddelegate_p.h +++ b/src/network/access/qhttpthreaddelegate_p.h @@ -135,6 +135,7 @@ signals: void proxyAuthenticationRequired(const QNetworkProxy &, QAuthenticator *); #endif #ifndef QT_NO_SSL + void encrypted(); void sslErrors(const QList<QSslError> &, bool *, QList<QSslError> *); void sslConfigurationChanged(const QSslConfiguration); #endif @@ -164,6 +165,7 @@ protected slots: void dataReadProgressSlot(qint64 done, qint64 total); void cacheCredentialsSlot(const QHttpNetworkRequest &request, QAuthenticator *authenticator); #ifndef QT_NO_SSL + void encryptedSlot(); void sslErrorsSlot(const QList<QSslError> &errors); #endif diff --git a/src/network/access/qnetworkaccessbackend.cpp b/src/network/access/qnetworkaccessbackend.cpp index 84f9b82a22..a895864d76 100644 --- a/src/network/access/qnetworkaccessbackend.cpp +++ b/src/network/access/qnetworkaccessbackend.cpp @@ -340,6 +340,13 @@ void QNetworkAccessBackend::redirectionRequested(const QUrl &target) reply->redirectionRequested(target); } +void QNetworkAccessBackend::encrypted() +{ +#ifndef QT_NO_SSL + reply->encrypted(); +#endif +} + void QNetworkAccessBackend::sslErrors(const QList<QSslError> &errors) { #ifndef QT_NO_SSL diff --git a/src/network/access/qnetworkaccessbackend_p.h b/src/network/access/qnetworkaccessbackend_p.h index 23f8416e0e..bf284414e0 100644 --- a/src/network/access/qnetworkaccessbackend_p.h +++ b/src/network/access/qnetworkaccessbackend_p.h @@ -196,6 +196,7 @@ protected slots: void authenticationRequired(QAuthenticator *auth); void metaDataChanged(); void redirectionRequested(const QUrl &destination); + void encrypted(); void sslErrors(const QList<QSslError> &errors); void emitReplyUploadProgress(qint64 bytesSent, qint64 bytesTotal); diff --git a/src/network/access/qnetworkaccessdebugpipebackend.cpp b/src/network/access/qnetworkaccessdebugpipebackend.cpp index d9d3200564..b6c04dddea 100644 --- a/src/network/access/qnetworkaccessdebugpipebackend.cpp +++ b/src/network/access/qnetworkaccessdebugpipebackend.cpp @@ -143,7 +143,7 @@ void QNetworkAccessDebugPipeBackend::pushFromSocketToDownstream() buffer.resize(ReadBufferSize); qint64 haveRead = socket.read(buffer.data(), ReadBufferSize); - + if (haveRead == -1) { hasDownloadFinished = true; // this ensures a good last downloadProgress is emitted diff --git a/src/network/access/qnetworkaccessfilebackend.cpp b/src/network/access/qnetworkaccessfilebackend.cpp index a7f35815f9..13428cc802 100644 --- a/src/network/access/qnetworkaccessfilebackend.cpp +++ b/src/network/access/qnetworkaccessfilebackend.cpp @@ -65,7 +65,11 @@ QNetworkAccessFileBackendFactory::create(QNetworkAccessManager::Operation op, } QUrl url = request.url(); - if (url.scheme().compare(QLatin1String("qrc"), Qt::CaseInsensitive) == 0 || url.isLocalFile()) { + if (url.scheme().compare(QLatin1String("qrc"), Qt::CaseInsensitive) == 0 +#if defined(Q_OS_ANDROID) + || url.scheme().compare(QLatin1String("assets"), Qt::CaseInsensitive) == 0 +#endif + || url.isLocalFile()) { return new QNetworkAccessFileBackend; } else if (!url.scheme().isEmpty() && url.authority().isEmpty() && (url.scheme().length() > 1)) { // check if QFile could, in theory, open this URL via the file engines @@ -113,10 +117,16 @@ void QNetworkAccessFileBackend::open() QString fileName = url.toLocalFile(); if (fileName.isEmpty()) { - if (url.scheme() == QLatin1String("qrc")) + if (url.scheme() == QLatin1String("qrc")) { fileName = QLatin1Char(':') + url.path(); - else - fileName = url.toString(QUrl::RemoveAuthority | QUrl::RemoveFragment | QUrl::RemoveQuery); + } else { +#if defined(Q_OS_ANDROID) + if (url.scheme() == QLatin1String("assets")) + fileName = QLatin1String("assets:") + url.path(); + else +#endif + fileName = url.toString(QUrl::RemoveAuthority | QUrl::RemoveFragment | QUrl::RemoveQuery); + } } file.setFileName(fileName); diff --git a/src/network/access/qnetworkaccessmanager.cpp b/src/network/access/qnetworkaccessmanager.cpp index 6899653800..83cb729589 100644 --- a/src/network/access/qnetworkaccessmanager.cpp +++ b/src/network/access/qnetworkaccessmanager.cpp @@ -374,6 +374,32 @@ static void ensureInitialized() */ /*! + \fn void QNetworkAccessManager::encrypted(QNetworkReply *reply) + \since 5.1 + + This signal is emitted when an SSL/TLS session has successfully + completed the initial handshake. At this point, no user data + has been transmitted. The signal can be used to perform + additional checks on the certificate chain, for example to + notify users when the certificate for a website has changed. The + \a reply parameter specifies which network reply is responsible. + If the reply does not match the expected criteria then it should + be aborted by calling QNetworkReply::abort() by a slot connected + to this signal. The SSL configuration in use can be inspected + using the QNetworkReply::sslConfiguration() method. + + Internally, QNetworkAccessManager may open multiple connections + to a server, in order to allow it process requests in parallel. + These connections may be reused, which means that the encrypted() + signal would not be emitted. This means that you are only + guaranteed to receive this signal for the first connection to a + site in the lifespan of the QNetworkAccessManager. + + \sa QSslSocket::encrypted() + \sa QNetworkReply::encrypted() +*/ + +/*! \fn void QNetworkAccessManager::sslErrors(QNetworkReply *reply, const QList<QSslError> &errors) This signal is emitted if the SSL/TLS session encountered errors @@ -646,8 +672,8 @@ QNetworkReply *QNetworkAccessManager::head(const QNetworkRequest &request) /*! Posts a request to obtain the contents of the target \a request - and returns a new QNetworkReply object opened for reading which emits the - \l{QIODevice::readyRead()}{readyRead()} signal whenever new data + and returns a new QNetworkReply object opened for reading which emits the + \l{QIODevice::readyRead()}{readyRead()} signal whenever new data arrives. The contents as well as associated headers will be downloaded. @@ -661,11 +687,11 @@ QNetworkReply *QNetworkAccessManager::get(const QNetworkRequest &request) /*! Sends an HTTP POST request to the destination specified by \a request - and returns a new QNetworkReply object opened for reading that will - contain the reply sent by the server. The contents of the \a data + and returns a new QNetworkReply object opened for reading that will + contain the reply sent by the server. The contents of the \a data device will be uploaded to the server. - \a data must be open for reading and must remain valid until the + \a data must be open for reading and must remain valid until the finished() signal is emitted for this reply. \note Sending a POST request on protocols other than HTTP and @@ -681,7 +707,7 @@ QNetworkReply *QNetworkAccessManager::post(const QNetworkRequest &request, QIODe /*! \overload - Sends the contents of the \a data byte array to the destination + Sends the contents of the \a data byte array to the destination specified by \a request. */ QNetworkReply *QNetworkAccessManager::post(const QNetworkRequest &request, const QByteArray &data) @@ -744,8 +770,8 @@ QNetworkReply *QNetworkAccessManager::put(const QNetworkRequest &request, QHttpM this reply. Whether anything will be available for reading from the returned - object is protocol dependent. For HTTP, the server may send a - small HTML page indicating the upload was successful (or not). + object is protocol dependent. For HTTP, the server may send a + small HTML page indicating the upload was successful (or not). Other protocols will probably have content in their replies. \note For HTTP, this request will send a PUT request, which most servers @@ -781,7 +807,7 @@ QNetworkReply *QNetworkAccessManager::put(const QNetworkRequest &request, const Sends a request to delete the resource identified by the URL of \a request. - \note This feature is currently available for HTTP only, performing an + \note This feature is currently available for HTTP only, performing an HTTP DELETE request. \sa get(), post(), put(), sendCustomRequest() @@ -834,10 +860,12 @@ QNetworkConfiguration QNetworkAccessManager::configuration() const Q_D(const QNetworkAccessManager); QSharedPointer<QNetworkSession> session(d->getNetworkSession()); - if (session) + if (session) { return session->configuration(); - else - return QNetworkConfiguration(); + } else { + QNetworkConfigurationManager manager; + return manager.defaultConfiguration(); + } } /*! @@ -860,13 +888,12 @@ QNetworkConfiguration QNetworkAccessManager::activeConfiguration() const Q_D(const QNetworkAccessManager); QSharedPointer<QNetworkSession> networkSession(d->getNetworkSession()); + QNetworkConfigurationManager manager; if (networkSession) { - QNetworkConfigurationManager manager; - return manager.configurationFromIdentifier( networkSession->sessionProperty(QLatin1String("ActiveConfiguration")).toString()); } else { - return QNetworkConfiguration(); + return manager.defaultConfiguration(); } } @@ -983,7 +1010,11 @@ QNetworkReply *QNetworkAccessManager::createRequest(QNetworkAccessManager::Opera // fast path for GET on file:// URLs // The QNetworkAccessFileBackend will right now only be used for PUT if ((op == QNetworkAccessManager::GetOperation || op == QNetworkAccessManager::HeadOperation) - && (isLocalFile || scheme == QLatin1String("qrc"))) { + && (isLocalFile || scheme == QLatin1String("qrc") +#if defined(Q_OS_ANDROID) + || scheme == QLatin1String("assets") +#endif + )) { return new QNetworkReplyFileImpl(this, req, op); } @@ -1131,6 +1162,16 @@ void QNetworkAccessManagerPrivate::_q_replyFinished() #endif } +void QNetworkAccessManagerPrivate::_q_replyEncrypted() +{ +#ifndef QT_NO_SSL + Q_Q(QNetworkAccessManager); + QNetworkReply *reply = qobject_cast<QNetworkReply *>(q->sender()); + if (reply) + emit q->encrypted(reply); +#endif +} + void QNetworkAccessManagerPrivate::_q_replySslErrors(const QList<QSslError> &errors) { #ifndef QT_NO_SSL @@ -1151,6 +1192,7 @@ QNetworkReply *QNetworkAccessManagerPrivate::postProcess(QNetworkReply *reply) #ifndef QT_NO_SSL /* In case we're compiled without SSL support, we don't have this signal and we need to * avoid getting a connection error. */ + q->connect(reply, SIGNAL(encrypted()), SLOT(_q_replyEncrypted())); q->connect(reply, SIGNAL(sslErrors(QList<QSslError>)), SLOT(_q_replySslErrors(QList<QSslError>))); #endif #ifndef QT_NO_BEARERMANAGEMENT diff --git a/src/network/access/qnetworkaccessmanager.h b/src/network/access/qnetworkaccessmanager.h index af5f6933a4..826c8e47d7 100644 --- a/src/network/access/qnetworkaccessmanager.h +++ b/src/network/access/qnetworkaccessmanager.h @@ -44,8 +44,6 @@ #include <QtCore/QObject> -QT_BEGIN_HEADER - QT_BEGIN_NAMESPACE @@ -141,6 +139,7 @@ Q_SIGNALS: void authenticationRequired(QNetworkReply *reply, QAuthenticator *authenticator); void finished(QNetworkReply *reply); #ifndef QT_NO_SSL + void encrypted(QNetworkReply *reply); void sslErrors(QNetworkReply *reply, const QList<QSslError> &errors); #endif @@ -161,6 +160,7 @@ private: Q_DECLARE_PRIVATE(QNetworkAccessManager) Q_PRIVATE_SLOT(d_func(), void _q_replyFinished()) + Q_PRIVATE_SLOT(d_func(), void _q_replyEncrypted()) Q_PRIVATE_SLOT(d_func(), void _q_replySslErrors(QList<QSslError>)) #ifndef QT_NO_BEARERMANAGEMENT Q_PRIVATE_SLOT(d_func(), void _q_networkSessionClosed()) @@ -170,6 +170,4 @@ private: QT_END_NAMESPACE -QT_END_HEADER - #endif diff --git a/src/network/access/qnetworkaccessmanager_p.h b/src/network/access/qnetworkaccessmanager_p.h index b4ad3511fa..cf756dad7b 100644 --- a/src/network/access/qnetworkaccessmanager_p.h +++ b/src/network/access/qnetworkaccessmanager_p.h @@ -90,6 +90,7 @@ public: ~QNetworkAccessManagerPrivate(); void _q_replyFinished(); + void _q_replyEncrypted(); void _q_replySslErrors(const QList<QSslError> &errors); QNetworkReply *postProcess(QNetworkReply *reply); void createCookieJar() const; diff --git a/src/network/access/qnetworkcookie.h b/src/network/access/qnetworkcookie.h index e7f6c8fe3f..2a4e686b2c 100644 --- a/src/network/access/qnetworkcookie.h +++ b/src/network/access/qnetworkcookie.h @@ -47,8 +47,6 @@ #include <QtCore/QMetaType> #include <QtCore/QObject> -QT_BEGIN_HEADER - QT_BEGIN_NAMESPACE @@ -121,6 +119,4 @@ QT_END_NAMESPACE Q_DECLARE_METATYPE(QNetworkCookie) -QT_END_HEADER - #endif diff --git a/src/network/access/qnetworkcookiejar.h b/src/network/access/qnetworkcookiejar.h index 7868e1fc04..3c787c5dd8 100644 --- a/src/network/access/qnetworkcookiejar.h +++ b/src/network/access/qnetworkcookiejar.h @@ -45,8 +45,6 @@ #include <QtCore/QObject> #include <QtCore/QUrl> -QT_BEGIN_HEADER - QT_BEGIN_NAMESPACE @@ -79,6 +77,4 @@ private: QT_END_NAMESPACE -QT_END_HEADER - #endif diff --git a/src/network/access/qnetworkdiskcache.h b/src/network/access/qnetworkdiskcache.h index 1d5f293a2c..20a412c96e 100644 --- a/src/network/access/qnetworkdiskcache.h +++ b/src/network/access/qnetworkdiskcache.h @@ -44,8 +44,6 @@ #include <QtNetwork/qabstractnetworkcache.h> -QT_BEGIN_HEADER - QT_BEGIN_NAMESPACE @@ -91,6 +89,4 @@ private: QT_END_NAMESPACE -QT_END_HEADER - #endif // QNETWORKDISKCACHE_H diff --git a/src/network/access/qnetworkreply.cpp b/src/network/access/qnetworkreply.cpp index fd3b7760cb..dc42adc612 100644 --- a/src/network/access/qnetworkreply.cpp +++ b/src/network/access/qnetworkreply.cpp @@ -195,6 +195,31 @@ QNetworkReplyPrivate::QNetworkReplyPrivate() */ /*! + \fn void QNetworkReply::encrypted() + \since 5.1 + + This signal is emitted when an SSL/TLS session has successfully + completed the initial handshake. At this point, no user data + has been transmitted. The signal can be used to perform + additional checks on the certificate chain, for example to + notify users when the certificate for a website has changed. + If the reply does not match the expected criteria then it should + be aborted by calling QNetworkReply::abort() by a slot connected + to this signal. The SSL configuration in use can be inspected + using the QNetworkReply::sslConfiguration() method. + + Internally, QNetworkAccessManager may open multiple connections + to a server, in order to allow it process requests in parallel. + These connections may be reused, which means that the encrypted() + signal would not be emitted. This means that you are only + guaranteed to receive this signal for the first connection to a + site in the lifespan of the QNetworkAccessManager. + + \sa QSslSocket::encrypted() + \sa QNetworkAccessManager::encrypted() +*/ + +/*! \fn void QNetworkReply::sslErrors(const QList<QSslError> &errors) This signal is emitted if the SSL/TLS session encountered errors diff --git a/src/network/access/qnetworkreply.h b/src/network/access/qnetworkreply.h index 8e770bc96b..a7db2d189c 100644 --- a/src/network/access/qnetworkreply.h +++ b/src/network/access/qnetworkreply.h @@ -49,8 +49,6 @@ #include <QtNetwork/QNetworkRequest> #include <QtNetwork/QNetworkAccessManager> -QT_BEGIN_HEADER - QT_BEGIN_NAMESPACE @@ -150,6 +148,7 @@ Q_SIGNALS: void finished(); void error(QNetworkReply::NetworkError); #ifndef QT_NO_SSL + void encrypted(); void sslErrors(const QList<QSslError> &errors); #endif @@ -182,6 +181,4 @@ QT_END_NAMESPACE Q_DECLARE_METATYPE(QNetworkReply::NetworkError) -QT_END_HEADER - #endif diff --git a/src/network/access/qnetworkreplyfileimpl.cpp b/src/network/access/qnetworkreplyfileimpl.cpp index 8a8f73c24f..f7555f8fc3 100644 --- a/src/network/access/qnetworkreplyfileimpl.cpp +++ b/src/network/access/qnetworkreplyfileimpl.cpp @@ -91,10 +91,16 @@ QNetworkReplyFileImpl::QNetworkReplyFileImpl(QObject *parent, const QNetworkRequ QString fileName = url.toLocalFile(); if (fileName.isEmpty()) { - if (url.scheme() == QLatin1String("qrc")) + if (url.scheme() == QLatin1String("qrc")) { fileName = QLatin1Char(':') + url.path(); - else - fileName = url.toString(QUrl::RemoveAuthority | QUrl::RemoveFragment | QUrl::RemoveQuery); + } else { +#if defined(Q_OS_ANDROID) + if (url.scheme() == QLatin1String("assets")) + fileName = QLatin1String("assets:") + url.path(); + else +#endif + fileName = url.toString(QUrl::RemoveAuthority | QUrl::RemoveFragment | QUrl::RemoveQuery); + } } QFileInfo fi(fileName); diff --git a/src/network/access/qnetworkreplyhttpimpl.cpp b/src/network/access/qnetworkreplyhttpimpl.cpp index 1520816e8d..c04421e5c7 100644 --- a/src/network/access/qnetworkreplyhttpimpl.cpp +++ b/src/network/access/qnetworkreplyhttpimpl.cpp @@ -610,14 +610,14 @@ void QNetworkReplyHttpImplPrivate::postRequest() if (synchronous) { // A synchronous HTTP request uses its own thread thread = new QThread(); - thread->setObjectName(QStringLiteral("httpReply")); + thread->setObjectName(QStringLiteral("Qt HTTP synchronous thread")); QObject::connect(thread, SIGNAL(finished()), thread, SLOT(deleteLater())); thread->start(); } else if (!managerPrivate->httpThread) { // We use the manager-global thread. // At some point we could switch to having multiple threads if it makes sense. managerPrivate->httpThread = new QThread(); - managerPrivate->httpThread->setObjectName(QStringLiteral("httpThread")); + managerPrivate->httpThread->setObjectName(QStringLiteral("Qt HTTP thread")); managerPrivate->httpThread->start(); thread = managerPrivate->httpThread; @@ -830,6 +830,8 @@ void QNetworkReplyHttpImplPrivate::postRequest() Qt::BlockingQueuedConnection); #endif #ifndef QT_NO_SSL + QObject::connect(delegate, SIGNAL(encrypted()), q, SLOT(replyEncrypted()), + Qt::BlockingQueuedConnection); QObject::connect(delegate, SIGNAL(sslErrors(QList<QSslError>,bool*,QList<QSslError>*)), q, SLOT(replySslErrors(QList<QSslError>,bool*,QList<QSslError>*)), Qt::BlockingQueuedConnection); @@ -1220,6 +1222,12 @@ void QNetworkReplyHttpImplPrivate::httpError(QNetworkReply::NetworkError errorCo } #ifndef QT_NO_SSL +void QNetworkReplyHttpImplPrivate::replyEncrypted() +{ + Q_Q(QNetworkReplyHttpImpl); + emit q->encrypted(); +} + void QNetworkReplyHttpImplPrivate::replySslErrors( const QList<QSslError> &list, bool *ignoreAll, QList<QSslError> *toBeIgnored) { diff --git a/src/network/access/qnetworkreplyhttpimpl_p.h b/src/network/access/qnetworkreplyhttpimpl_p.h index 5f8f0badf7..15cc0ec476 100644 --- a/src/network/access/qnetworkreplyhttpimpl_p.h +++ b/src/network/access/qnetworkreplyhttpimpl_p.h @@ -116,6 +116,7 @@ public: Q_PRIVATE_SLOT(d_func(), void httpAuthenticationRequired(const QHttpNetworkRequest &, QAuthenticator *)) Q_PRIVATE_SLOT(d_func(), void httpError(QNetworkReply::NetworkError, const QString &)) #ifndef QT_NO_SSL + Q_PRIVATE_SLOT(d_func(), void replyEncrypted()) Q_PRIVATE_SLOT(d_func(), void replySslErrors(const QList<QSslError> &, bool *, QList<QSslError> *)) Q_PRIVATE_SLOT(d_func(), void replySslConfigurationChanged(const QSslConfiguration&)) #endif @@ -280,6 +281,7 @@ public: void httpAuthenticationRequired(const QHttpNetworkRequest &request, QAuthenticator *auth); void httpError(QNetworkReply::NetworkError error, const QString &errorString); #ifndef QT_NO_SSL + void replyEncrypted(); void replySslErrors(const QList<QSslError> &, bool *, QList<QSslError> *); void replySslConfigurationChanged(const QSslConfiguration&); #endif diff --git a/src/network/access/qnetworkreplyimpl.cpp b/src/network/access/qnetworkreplyimpl.cpp index e12286c459..33357293a3 100644 --- a/src/network/access/qnetworkreplyimpl.cpp +++ b/src/network/access/qnetworkreplyimpl.cpp @@ -879,6 +879,14 @@ void QNetworkReplyImplPrivate::redirectionRequested(const QUrl &target) attributes.insert(QNetworkRequest::RedirectionTargetAttribute, target); } +void QNetworkReplyImplPrivate::encrypted() +{ +#ifndef QT_NO_SSL + Q_Q(QNetworkReplyImpl); + emit q->encrypted(); +#endif +} + void QNetworkReplyImplPrivate::sslErrors(const QList<QSslError> &errors) { #ifndef QT_NO_SSL diff --git a/src/network/access/qnetworkreplyimpl_p.h b/src/network/access/qnetworkreplyimpl_p.h index ca9a3b5fd1..9edc0f6b59 100644 --- a/src/network/access/qnetworkreplyimpl_p.h +++ b/src/network/access/qnetworkreplyimpl_p.h @@ -176,6 +176,7 @@ public: void error(QNetworkReply::NetworkError code, const QString &errorString); void metaDataChanged(); void redirectionRequested(const QUrl &target); + void encrypted(); void sslErrors(const QList<QSslError> &errors); QNetworkAccessBackend *backend; diff --git a/src/network/access/qnetworkrequest.h b/src/network/access/qnetworkrequest.h index 0d3c72d18a..1512c6dadd 100644 --- a/src/network/access/qnetworkrequest.h +++ b/src/network/access/qnetworkrequest.h @@ -47,8 +47,6 @@ #include <QtCore/QUrl> #include <QtCore/QVariant> -QT_BEGIN_HEADER - QT_BEGIN_NAMESPACE @@ -159,6 +157,4 @@ QT_END_NAMESPACE Q_DECLARE_METATYPE(QNetworkRequest) -QT_END_HEADER - #endif |