diff options
author | Shane Kearns <ext-shane.2.kearns@nokia.com> | 2012-02-15 17:24:14 +0000 |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2012-02-20 17:27:31 +0100 |
commit | 0cd1a21f55863740c3c7b4f69a0d73f0089b03aa (patch) | |
tree | 6c580ffe98779848d3bec350c9d98d940bab5b49 /src | |
parent | f0f9677a875510c82d9b6918322194f7dcb35abd (diff) | |
download | qt4-tools-0cd1a21f55863740c3c7b4f69a0d73f0089b03aa.tar.gz |
Fix handling of urls containing username/password in QNetworkAccessManager
QNetworkAccessManager was ignoring the supplied credentials, although
webkit seems to support these urls at a higher level.
Following the behaviour of browsers:
We use supplied credentials if authentication is required.
We add supplied credentials to the authentication cache.
We emit authenticationRequired signal if the credentials were wrong.
We do not use previously cached credentials for that url
Synchronous http requests fail, if the credentials were wrong.
Task-number: QTBUG-18107
Change-Id: If46e8eab1511ba8a0f4bbe0d4efaabc4df0b8ab4
Reviewed-by: Richard J. Moore <rich@kde.org>
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
(cherry picked from commit b4a538ea1c3cdce09e3528227dba2e8f5765cbdc)
Diffstat (limited to 'src')
-rw-r--r-- | src/network/access/qnetworkaccessmanager.cpp | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/src/network/access/qnetworkaccessmanager.cpp b/src/network/access/qnetworkaccessmanager.cpp index 30efac27e7..58690fa6ad 100644 --- a/src/network/access/qnetworkaccessmanager.cpp +++ b/src/network/access/qnetworkaccessmanager.cpp @@ -1068,6 +1068,16 @@ void QNetworkAccessManagerPrivate::authenticationRequired(QNetworkAccessBackend // also called when last URL is empty, e.g. on first call if (backend->reply->urlForLastAuthentication.isEmpty() || url != backend->reply->urlForLastAuthentication) { + // if credentials are included in the url, then use them + if (!url.userName().isEmpty() + && !url.password().isEmpty()) { + authenticator->setUser(url.userName()); + authenticator->setPassword(url.password()); + backend->reply->urlForLastAuthentication = url; + authenticationManager->cacheCredentials(url, authenticator); + return; + } + QNetworkAuthenticationCredential cred = authenticationManager->fetchCachedCredentials(url, authenticator); if (!cred.isNull()) { authenticator->setUser(cred.user); |