summaryrefslogtreecommitdiffstats
path: root/src/network
diff options
context:
space:
mode:
authorLiang Qi <liang.qi@qt.io>2017-10-04 10:41:19 +0200
committerLiang Qi <liang.qi@qt.io>2017-10-04 13:41:04 +0200
commitbc5f45052fd8f9a5481a37a6a4d55c7f6cbf037d (patch)
tree2c20e6c42ccd008e431a8d485450713883eacbb5 /src/network
parentb8947e9194f0f88f464448ac51f6a05113d36a33 (diff)
parent3faf8f4d48abd982be8470786cc5f61372519722 (diff)
Merge remote-tracking branch 'origin/5.9' into 5.10
Conflicts: src/corelib/global/qconfig-bootstrapped.h src/corelib/global/qglobal.h src/corelib/tools/qcryptographichash.cpp src/corelib/tools/qcryptographichash.h src/corelib/tools/qmessageauthenticationcode.cpp src/plugins/platforms/windows/qwindowswindow.h tests/auto/gui/kernel/qwindow/BLACKLIST tests/auto/widgets/itemviews/qitemdelegate/BLACKLIST Change-Id: Ib68112de985a3d714c2071f47c10e907e4f0229a
Diffstat (limited to 'src/network')
-rw-r--r--src/network/access/qhttp2protocolhandler.cpp21
-rw-r--r--src/network/access/qnetworkaccessmanager.cpp11
-rw-r--r--src/network/access/qnetworkreplyhttpimpl.cpp8
-rw-r--r--src/network/socket/qabstractsocket.cpp38
-rw-r--r--src/network/socket/qabstractsocket.h1
-rw-r--r--src/network/socket/qabstractsocket_p.h2
6 files changed, 42 insertions, 39 deletions
diff --git a/src/network/access/qhttp2protocolhandler.cpp b/src/network/access/qhttp2protocolhandler.cpp
index 5032f6017f..a651fc4092 100644
--- a/src/network/access/qhttp2protocolhandler.cpp
+++ b/src/network/access/qhttp2protocolhandler.cpp
@@ -1042,12 +1042,26 @@ void QHttp2ProtocolHandler::updateStream(Stream &stream, const HPack::HttpHeader
}
const auto httpReplyPrivate = httpReply->d_func();
+
+ // For HTTP/1 'location' is handled (and redirect URL set) when a protocol
+ // handler emits channel->allDone(). Http/2 protocol handler never emits
+ // allDone, since we have many requests multiplexed in one channel at any
+ // moment and we are probably not done yet. So we extract url and set it
+ // here, if needed.
+ int statusCode = 0;
+ QUrl redirectUrl;
+
for (const auto &pair : headers) {
const auto &name = pair.name;
auto value = pair.value;
+ // TODO: part of this code copies what SPDY protocol handler does when
+ // processing headers. Binary nature of HTTP/2 and SPDY saves us a lot
+ // of parsing and related errors/bugs, but it would be nice to have
+ // more detailed validation of headers.
if (name == ":status") {
- httpReply->setStatusCode(value.left(3).toInt());
+ statusCode = value.left(3).toInt();
+ httpReply->setStatusCode(statusCode);
httpReplyPrivate->reasonPhrase = QString::fromLatin1(value.mid(4));
} else if (name == ":version") {
httpReplyPrivate->majorVersion = value.at(5) - '0';
@@ -1058,6 +1072,8 @@ void QHttp2ProtocolHandler::updateStream(Stream &stream, const HPack::HttpHeader
if (ok)
httpReply->setContentLength(length);
} else {
+ if (name == "location")
+ redirectUrl = QUrl::fromEncoded(value);
QByteArray binder(", ");
if (name == "set-cookie")
binder = "\n";
@@ -1065,6 +1081,9 @@ void QHttp2ProtocolHandler::updateStream(Stream &stream, const HPack::HttpHeader
}
}
+ if (QHttpNetworkReply::isHttpRedirect(statusCode) && redirectUrl.isValid())
+ httpReply->setRedirectUrl(redirectUrl);
+
if (connectionType == Qt::DirectConnection)
emit httpReply->headerChanged();
else
diff --git a/src/network/access/qnetworkaccessmanager.cpp b/src/network/access/qnetworkaccessmanager.cpp
index 8bbef0a0d8..edf9dee78e 100644
--- a/src/network/access/qnetworkaccessmanager.cpp
+++ b/src/network/access/qnetworkaccessmanager.cpp
@@ -75,6 +75,12 @@
#include <QHostInfo>
+#if defined(Q_OS_MACOS)
+#include <CoreServices/CoreServices.h>
+#include <SystemConfiguration/SystemConfiguration.h>
+#include <Security/SecKeychain.h>
+#endif
+
QT_BEGIN_NAMESPACE
Q_GLOBAL_STATIC(QNetworkAccessFileBackendFactory, fileBackend)
@@ -87,11 +93,6 @@ Q_GLOBAL_STATIC(QNetworkAccessDebugPipeBackendFactory, debugpipeBackend)
#endif
#if defined(Q_OS_MACX)
-
-#include <CoreServices/CoreServices.h>
-#include <SystemConfiguration/SystemConfiguration.h>
-#include <Security/SecKeychain.h>
-
bool getProxyAuth(const QString& proxyHostname, const QString &scheme, QString& username, QString& password)
{
OSStatus err;
diff --git a/src/network/access/qnetworkreplyhttpimpl.cpp b/src/network/access/qnetworkreplyhttpimpl.cpp
index 84b1ddf5ac..48255d175a 100644
--- a/src/network/access/qnetworkreplyhttpimpl.cpp
+++ b/src/network/access/qnetworkreplyhttpimpl.cpp
@@ -1169,6 +1169,14 @@ void QNetworkReplyHttpImplPrivate::onRedirected(const QUrl &redirectUrl, int htt
redirectRequest = createRedirectRequest(originalRequest, url, maxRedirectsRemaining);
operation = getRedirectOperation(operation, httpStatus);
+ if (const QNetworkCookieJar *const cookieJar = (manager ? manager->cookieJar() : nullptr)) {
+ auto cookies = cookieJar->cookiesForUrl(url);
+ if (!cookies.empty()) {
+ redirectRequest.setHeader(QNetworkRequest::KnownHeaders::CookieHeader,
+ QVariant::fromValue(cookies));
+ }
+ }
+
if (httpRequest.redirectPolicy() != QNetworkRequest::UserVerifiedRedirectPolicy)
followRedirect();
diff --git a/src/network/socket/qabstractsocket.cpp b/src/network/socket/qabstractsocket.cpp
index 9cb6c4be57..7284b124c5 100644
--- a/src/network/socket/qabstractsocket.cpp
+++ b/src/network/socket/qabstractsocket.cpp
@@ -565,7 +565,6 @@ QAbstractSocketPrivate::QAbstractSocketPrivate()
isBuffered(false),
hasPendingData(false),
connectTimer(0),
- disconnectTimer(0),
hostLookupId(-1),
socketType(QAbstractSocket::UnknownSocketType),
state(QAbstractSocket::UnconnectedState),
@@ -604,8 +603,6 @@ void QAbstractSocketPrivate::resetSocketLayer()
}
if (connectTimer)
connectTimer->stop();
- if (disconnectTimer)
- disconnectTimer->stop();
}
/*! \internal
@@ -967,13 +964,17 @@ void QAbstractSocketPrivate::startConnectingByName(const QString &host)
emit q->stateChanged(state);
if (cachedSocketDescriptor != -1 || initSocketLayer(QAbstractSocket::UnknownNetworkLayerProtocol)) {
- if (socketEngine->connectToHostByName(host, port) ||
- socketEngine->state() == QAbstractSocket::ConnectingState) {
- cachedSocketDescriptor = socketEngine->socketDescriptor();
-
+ // Try to connect to the host. If it succeeds immediately
+ // (e.g. QSocks5SocketEngine in UDPASSOCIATE mode), emit
+ // connected() and return.
+ if (socketEngine->connectToHostByName(host, port)) {
+ fetchConnectionParameters();
return;
}
+ if (socketEngine->state() == QAbstractSocket::ConnectingState)
+ return;
+
// failed to connect
setError(socketEngine->error(), socketEngine->errorString());
}
@@ -1220,15 +1221,6 @@ void QAbstractSocketPrivate::_q_abortConnectionAttempt()
}
}
-void QAbstractSocketPrivate::_q_forceDisconnect()
-{
- Q_Q(QAbstractSocket);
- if (socketEngine && socketEngine->isValid() && state == QAbstractSocket::ClosingState) {
- socketEngine->close();
- q->disconnectFromHost();
- }
-}
-
/*! \internal
Reads data from the socket layer into the read buffer. Returns
@@ -2756,20 +2748,6 @@ void QAbstractSocket::disconnectFromHost()
// Wait for pending data to be written.
if (d->socketEngine && d->socketEngine->isValid() && (!d->allWriteBuffersEmpty()
|| d->socketEngine->bytesToWrite() > 0)) {
- // hack: when we are waiting for the socket engine to write bytes (only
- // possible when using Socks5 or HTTP socket engine), then close
- // anyway after 2 seconds. This is to prevent a timeout on Mac, where we
- // sometimes just did not get the write notifier from the underlying
- // CFSocket and no progress was made.
- if (d->allWriteBuffersEmpty() && d->socketEngine->bytesToWrite() > 0) {
- if (!d->disconnectTimer) {
- d->disconnectTimer = new QTimer(this);
- connect(d->disconnectTimer, SIGNAL(timeout()), this,
- SLOT(_q_forceDisconnect()), Qt::DirectConnection);
- }
- if (!d->disconnectTimer->isActive())
- d->disconnectTimer->start(2000);
- }
d->socketEngine->setWriteNotificationEnabled(true);
#if defined(QABSTRACTSOCKET_DEBUG)
diff --git a/src/network/socket/qabstractsocket.h b/src/network/socket/qabstractsocket.h
index 73a8f11537..875609aa28 100644
--- a/src/network/socket/qabstractsocket.h
+++ b/src/network/socket/qabstractsocket.h
@@ -231,7 +231,6 @@ private:
Q_PRIVATE_SLOT(d_func(), void _q_startConnecting(const QHostInfo &))
Q_PRIVATE_SLOT(d_func(), void _q_abortConnectionAttempt())
Q_PRIVATE_SLOT(d_func(), void _q_testConnection())
- Q_PRIVATE_SLOT(d_func(), void _q_forceDisconnect())
};
diff --git a/src/network/socket/qabstractsocket_p.h b/src/network/socket/qabstractsocket_p.h
index 8a96cb9d48..5411133ea9 100644
--- a/src/network/socket/qabstractsocket_p.h
+++ b/src/network/socket/qabstractsocket_p.h
@@ -95,7 +95,6 @@ public:
void _q_startConnecting(const QHostInfo &hostInfo);
void _q_testConnection();
void _q_abortConnectionAttempt();
- void _q_forceDisconnect();
bool emittedReadyRead;
bool emittedBytesWritten;
@@ -148,7 +147,6 @@ public:
bool hasPendingData;
QTimer *connectTimer;
- QTimer *disconnectTimer;
int hostLookupId;