diff options
Diffstat (limited to 'src/network/access/qnetworkaccessmanager.cpp')
-rw-r--r-- | src/network/access/qnetworkaccessmanager.cpp | 74 |
1 files changed, 58 insertions, 16 deletions
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 |