QNAM: HTTP/2: Set user-agent for the HTTP proxy's header

The user-agent should be propagated to the proxy as well or else we
get our default one.

Change-Id: Id2283a8f2ade1a32f7fcf3d691be8d380d334b50
Reviewed-by: Timur Pocheptsov <timur.pocheptsov@qt.io>
This commit is contained in:
Mårten Nordheim 2020-08-12 16:11:11 +02:00
parent 5ecc6eb363
commit 7e55642c87

View File

@ -367,11 +367,20 @@ bool QHttpNetworkConnectionChannel::ensureConnection()
if (socket->proxy().type() == QNetworkProxy::HttpProxy) {
// Make user-agent field available to HTTP proxy socket engine (QTBUG-17223)
QByteArray value;
// ensureConnection is called before any request has been assigned, but can also be called again if reconnecting
if (request.url().isEmpty())
value = connection->d_func()->predictNextRequest().headerField("user-agent");
else
// ensureConnection is called before any request has been assigned, but can also be
// called again if reconnecting
if (request.url().isEmpty()) {
if (connection->connectionType()
== QHttpNetworkConnection::ConnectionTypeHTTP2Direct
|| (connection->connectionType() == QHttpNetworkConnection::ConnectionTypeHTTP2
&& h2RequestsToSend.count() > 0)) {
value = h2RequestsToSend.first().first.headerField("user-agent");
} else {
value = connection->d_func()->predictNextRequest().headerField("user-agent");
}
} else {
value = request.headerField("user-agent");
}
if (!value.isEmpty()) {
QNetworkProxy proxy(socket->proxy());
proxy.setRawHeader("User-Agent", value); //detaches