98 QString scheme = copy.scheme();
99 bool isEncrypted = scheme ==
"https"_L1 || scheme ==
"preconnect-https"_L1;
100 const bool isLocalSocket = scheme.startsWith(
"unix"_L1);
102 copy.setPort(copy.port(isEncrypted ? 443 : 80));
103 if (scheme ==
"preconnect-http"_L1)
104 copy.setScheme(
"http"_L1);
105 else if (scheme ==
"preconnect-https"_L1)
106 copy.setScheme(
"https"_L1);
107 result = copy.toString(QUrl::RemoveUserInfo | QUrl::RemovePath |
108 QUrl::RemoveQuery | QUrl::RemoveFragment | QUrl::FullyEncoded);
110#ifndef QT_NO_NETWORKPROXY
111 if (proxy && proxy->type() != QNetworkProxy::NoProxy) {
114 switch (proxy->type()) {
115 case QNetworkProxy::Socks5Proxy:
116 key.setScheme(
"proxy-socks5"_L1);
119 case QNetworkProxy::HttpProxy:
120 case QNetworkProxy::HttpCachingProxy:
121 key.setScheme(
"proxy-http"_L1);
128 if (!key.scheme().isEmpty()) {
129 const QByteArray obfuscatedPassword = QCryptographicHash::hash(proxy->password().toUtf8(),
130 QCryptographicHash::Sha1).toHex();
131 key.setUserName(proxy->user());
132 key.setPassword(QString::fromUtf8(obfuscatedPassword));
133 key.setHost(proxy->hostName());
134 key.setPort(proxy->port());
135 key.setQuery(result);
136 result = key.toString(QUrl::FullyEncoded);
142 if (!peerVerifyName.isEmpty())
143 result += u':' + peerVerifyName;
144 return "http-connection:" +
std::move(result).toLatin1();
240#ifdef QHTTPTHREADDELEGATE_DEBUG
241 qDebug() <<
"QHttpThreadDelegate::startRequest() thread=" << QThread::currentThreadId();
245 if (!connections.hasLocalData()) {
250 QUrl urlCopy = httpRequest.url();
251 const bool isLocalSocket = urlCopy.scheme().startsWith(
"unix"_L1);
253 urlCopy.setPort(urlCopy.port(
ssl ? 443 : 80));
255 QHttpNetworkConnection::ConnectionType connectionType
256 = httpRequest.isHTTP2Allowed() ? QHttpNetworkConnection::ConnectionTypeHTTP2
257 : QHttpNetworkConnection::ConnectionTypeHTTP;
258 if (httpRequest.isHTTP2Direct()) {
259 Q_ASSERT(!httpRequest.isHTTP2Allowed());
260 connectionType = QHttpNetworkConnection::ConnectionTypeHTTP2Direct;
264 if (!ssl && connectionType == QHttpNetworkConnection::ConnectionTypeHTTP2
265 && !httpRequest.isH2cAllowed()) {
266 connectionType = QHttpNetworkConnection::ConnectionTypeHTTP;
271 Q_ASSERT(!ssl || incomingSslConfiguration);
274 const bool isH2 = httpRequest.isHTTP2Allowed() || httpRequest.isHTTP2Direct();
278 if (!httpRequest.isHTTP2Direct()) {
279 QList<QByteArray> protocols;
280 protocols << QSslConfiguration::ALPNProtocolHTTP2
281 << QSslConfiguration::NextProtocolHttp1_1;
282 incomingSslConfiguration->setAllowedNextProtocols(protocols);
284 urlCopy.setScheme(QStringLiteral(
"h2s"));
289 urlCopy.setScheme(QStringLiteral(
"unix+h2"));
291 urlCopy.setScheme(QStringLiteral(
"h2"));
295 QString extraData = httpRequest.peerVerifyName();
297 if (QString path = httpRequest.fullLocalServerName(); !path.isEmpty())
301#ifndef QT_NO_NETWORKPROXY
302 if (transparentProxy.type() != QNetworkProxy::NoProxy)
303 cacheKey = makeCacheKey(urlCopy, &transparentProxy, httpRequest.peerVerifyName());
304 else if (cacheProxy.type() != QNetworkProxy::NoProxy)
305 cacheKey = makeCacheKey(urlCopy, &cacheProxy, httpRequest.peerVerifyName());
308 cacheKey = makeCacheKey(urlCopy,
nullptr, httpRequest.peerVerifyName());
311 httpConnection =
static_cast<QNetworkAccessCachedHttpConnection *>(connections.localData()->requestEntryNow(cacheKey));
314 QString host = urlCopy.host();
317 if (QString path = httpRequest.fullLocalServerName(); !path.isEmpty())
323 httpConnection =
new QNetworkAccessCachedHttpConnection(
324 http1Parameters.numberOfConnectionsPerHost(), host, urlCopy.port(), ssl,
325 isLocalSocket, connectionType);
326 if (connectionType == QHttpNetworkConnection::ConnectionTypeHTTP2
327 || connectionType == QHttpNetworkConnection::ConnectionTypeHTTP2Direct) {
328 httpConnection->setHttp2Parameters(http2Parameters);
333 httpConnection->setSslConfiguration(*incomingSslConfiguration);
336#ifndef QT_NO_NETWORKPROXY
337 httpConnection->setTransparentProxy(transparentProxy);
338 httpConnection->setCacheProxy(cacheProxy);
340 httpConnection->setPeerVerifyName(httpRequest.peerVerifyName());
342 connections.localData()->addEntry(cacheKey, httpConnection, connectionCacheExpiryTimeoutSeconds);
344 if (httpRequest.withCredentials()) {
346 if (!credential.user.isEmpty() && !credential.password.isEmpty()) {
348 auth.setUser(credential.user);
349 auth.setPassword(credential.password);
356 httpReply = httpConnection->sendRequest(httpRequest);
363 connect(httpReply,SIGNAL(finishedWithError(QNetworkReply::NetworkError,QString)),
364 this, SLOT(synchronousFinishedWithErrorSlot(QNetworkReply::NetworkError,QString)));
366 connect(httpReply, SIGNAL(authenticationRequired(QHttpNetworkRequest,QAuthenticator*)),
367 this, SLOT(synchronousAuthenticationRequiredSlot(QHttpNetworkRequest,QAuthenticator*)));
368#ifndef QT_NO_NETWORKPROXY
369 connect(httpReply, SIGNAL(proxyAuthenticationRequired(QNetworkProxy,QAuthenticator*)),
370 this, SLOT(synchronousProxyAuthenticationRequiredSlot(QNetworkProxy,QAuthenticator*)));
379 connect(httpReply,SIGNAL(finishedWithError(QNetworkReply::NetworkError,QString)),
380 this, SLOT(finishedWithErrorSlot(QNetworkReply::NetworkError,QString)));
382 connect(
httpReply,SIGNAL(readyRead()),
this, SLOT(readyReadSlot()));
383 connect(httpReply,SIGNAL(dataReadProgress(qint64,qint64)),
this, SLOT(dataReadProgressSlot(qint64,qint64)));
386 connect(httpReply,SIGNAL(sslErrors(QList<QSslError>)),
this, SLOT(sslErrorsSlot(QList<QSslError>)));
387 connect(httpReply,SIGNAL(preSharedKeyAuthenticationRequired(QSslPreSharedKeyAuthenticator*)),
388 this, SLOT(preSharedKeyAuthenticationRequiredSlot(QSslPreSharedKeyAuthenticator*)));
393 connect(httpReply, SIGNAL(authenticationRequired(QHttpNetworkRequest,QAuthenticator*)),
394 this, SIGNAL(authenticationRequired(QHttpNetworkRequest,QAuthenticator*)));
395#ifndef QT_NO_NETWORKPROXY
396 connect(httpReply, SIGNAL(proxyAuthenticationRequired(QNetworkProxy,QAuthenticator*)),
397 this, SIGNAL(proxyAuthenticationRequired(QNetworkProxy,QAuthenticator*)));
401 connect(httpReply, SIGNAL(cacheCredentials(QHttpNetworkRequest,QAuthenticator*)),
402 this, SLOT(cacheCredentialsSlot(QHttpNetworkRequest,QAuthenticator*)));
403 if (httpReply->errorCode() != QNetworkReply::NoError) {
405 synchronousFinishedWithErrorSlot(httpReply->errorCode(), httpReply->errorString());
407 finishedWithErrorSlot(httpReply->errorCode(), httpReply->errorString());