72 switch (proxy.type()) {
73 case QNetworkProxy::Socks5Proxy:
74 key.setScheme(
"proxy-socks5"_L1);
77 case QNetworkProxy::HttpProxy:
78 case QNetworkProxy::HttpCachingProxy:
79 key.setScheme(
"proxy-http"_L1);
82 case QNetworkProxy::FtpCachingProxy:
83 key.setScheme(
"proxy-ftp"_L1);
86 case QNetworkProxy::DefaultProxy:
87 case QNetworkProxy::NoProxy:
95 if (key.scheme().isEmpty())
99 key.setUserName(proxy.user());
100 key.setHost(proxy.hostName());
101 key.setPort(proxy.port());
102 key.setFragment(realm);
103 return "auth:" + key.toEncoded();
117 const QAuthenticator *authenticator)
119 Q_ASSERT(authenticator);
120 Q_ASSERT(p.type() != QNetworkProxy::DefaultProxy);
121 Q_ASSERT(p.type() != QNetworkProxy::NoProxy);
123 QMutexLocker mutexLocker(&mutex);
125 QString realm = authenticator->realm();
126 QNetworkProxy proxy = p;
127 proxy.setUser(authenticator->user());
130 if (authenticator->password().isNull())
137 QByteArray cacheKey = proxyAuthenticationKey(proxy, realm);
138 if (cacheKey.isEmpty())
142 auth->insert(QString(), authenticator->user(), authenticator->password());
143 authenticationCache.addEntry(cacheKey, auth);
145 if (realm.isEmpty()) {
152 if (proxy.user().isEmpty())
155 proxy.setUser(QString());
161 const QAuthenticator *authenticator)
163 QNetworkProxy proxy = p;
164 if (proxy.type() == QNetworkProxy::DefaultProxy) {
165 proxy = QNetworkProxy::applicationProxy();
167 if (!proxy.password().isEmpty())
172 realm = authenticator->realm();
174 QMutexLocker mutexLocker(&mutex);
175 QByteArray cacheKey = proxyAuthenticationKey(proxy, realm);
176 if (cacheKey.isEmpty())
178 if (!authenticationCache.hasEntry(cacheKey))
182 static_cast<QNetworkAuthenticationCache *>(authenticationCache.requestEntryNow(cacheKey));
184 authenticationCache.releaseEntry(cacheKey);
187 Q_ASSERT_X(!cred
.isNull(),
"QNetworkAccessManager",
188 "Internal inconsistency: found a cache key for a proxy, but it's empty");
195 const QAuthenticator *authenticator)
197 Q_ASSERT(authenticator);
198 if (authenticator->isNull())
200 QString domain = QString::fromLatin1(
"/");
201 QString realm = authenticator->realm();
203 QMutexLocker mutexLocker(&mutex);
207 copy.setUserName(authenticator->user());
209 QByteArray cacheKey = authenticationKey(copy, realm);
210 if (authenticationCache.hasEntry(cacheKey)) {
212 static_cast<QNetworkAuthenticationCache *>(authenticationCache.requestEntryNow(cacheKey));
213 auth->insert(domain, authenticator->user(), authenticator->password());
214 authenticationCache.releaseEntry(cacheKey);
217 auth->insert(domain, authenticator->user(), authenticator->password());
218 authenticationCache.addEntry(cacheKey, auth);
221 if (copy.userName().isEmpty()) {
224 copy.setUserName(QString());
247 const QAuthenticator *authentication)
249 if (!url.password().isEmpty())
254 realm = authentication->realm();
256 QByteArray cacheKey = authenticationKey(url, realm);
258 QMutexLocker mutexLocker(&mutex);
259 if (!authenticationCache.hasEntry(cacheKey))
263 static_cast<QNetworkAuthenticationCache *>(authenticationCache.requestEntryNow(cacheKey));
264 auto cred = auth->findClosestMatch(url.path());
266 if (cred != auth->end())
268 authenticationCache.releaseEntry(cacheKey);