diff options
author | Shane Kearns <shane.kearns@accenture.com> | 2011-05-04 16:27:36 (GMT) |
---|---|---|
committer | Shane Kearns <shane.kearns@accenture.com> | 2011-05-05 14:22:56 (GMT) |
commit | 5b356ab162c58442a5e08868412af1b2b65b3f5c (patch) | |
tree | 35742bb2e77cfeca0a7e0411d8fd84f4eb35e07e /src/network/socket | |
parent | b166c30d8d0834518337ded44d2ebfe097ee312f (diff) | |
download | Qt-5b356ab162c58442a5e08868412af1b2b65b3f5c.zip Qt-5b356ab162c58442a5e08868412af1b2b65b3f5c.tar.gz Qt-5b356ab162c58442a5e08868412af1b2b65b3f5c.tar.bz2 |
Send User-Agent from the network request in http proxy CONNECT command
Some proxies can discriminate based on the User-Agent when sent a
CONNECT command for establishing a HTTPS connection.
With this change, if the User-Agent header is set in the QNetworkRequest
then it will be passed to the http socket engine for use in the connect
command sent to the proxy.
As before, "Mozilla/5.0" will be used by default when no user agent
has been set.
Task-number: QTBUG-17223
Reviewed-by: Markus Goetz
Diffstat (limited to 'src/network/socket')
-rw-r--r-- | src/network/socket/qabstractsocket.cpp | 4 | ||||
-rw-r--r-- | src/network/socket/qhttpsocketengine.cpp | 8 |
2 files changed, 11 insertions, 1 deletions
diff --git a/src/network/socket/qabstractsocket.cpp b/src/network/socket/qabstractsocket.cpp index 7af71cc..090f092 100644 --- a/src/network/socket/qabstractsocket.cpp +++ b/src/network/socket/qabstractsocket.cpp @@ -556,6 +556,10 @@ bool QAbstractSocketPrivate::initSocketLayer(QAbstractSocket::NetworkLayerProtoc q->setErrorString(QAbstractSocket::tr("Operation on socket is not supported")); return false; } +#ifndef QT_NO_NETWORKPROXY + //copy user agent to socket engine (if it has been set) + socketEngine->setProperty("_q_user-agent", q->property("_q_user-agent")); +#endif if (!socketEngine->initialize(q->socketType(), protocol)) { #if defined (QABSTRACTSOCKET_DEBUG) qDebug("QAbstractSocketPrivate::initSocketLayer(%s, %s) failed (%s)", diff --git a/src/network/socket/qhttpsocketengine.cpp b/src/network/socket/qhttpsocketengine.cpp index 7846056..a8a11a7 100644 --- a/src/network/socket/qhttpsocketengine.cpp +++ b/src/network/socket/qhttpsocketengine.cpp @@ -501,7 +501,13 @@ void QHttpSocketEngine::slotSocketConnected() data += path; data += " HTTP/1.1\r\n"; data += "Proxy-Connection: keep-alive\r\n" - "User-Agent: Mozilla/5.0\r\n" + "User-Agent: "; + QVariant v = property("_q_user-agent"); + if (v.isValid()) + data += v.toByteArray(); + else + data += "Mozilla/5.0"; + data += "\r\n" "Host: " + peerAddress + "\r\n"; QAuthenticatorPrivate *priv = QAuthenticatorPrivate::getPrivate(d->authenticator); //qDebug() << "slotSocketConnected: priv=" << priv << (priv ? (int)priv->method : -1); |