Remove zone id from IPv6 host in prepareRequest
Ensure that link-local IPv6 addresses in a HTTP Request do not include the zone identifier in the 'Host' header, as per RFC 6874. This prevents connection failures due to invalid host syntax. Fixes: QTBUG-134727 Change-Id: I7067a991f67d44241717a89b656a3fcbda1fcd3a Reviewed-by: Øystein Heskestad <oystein.heskestad@qt.io> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
This commit is contained in:
parent
3cc947e98f
commit
5db60be476
@ -234,6 +234,18 @@ static QByteArray makeAcceptLanguage()
|
||||
return (systemLocale + ",en,*"_L1).toLatin1();
|
||||
}
|
||||
|
||||
static QStringView removeZoneId(QStringView ipv6HostAddress)
|
||||
{
|
||||
const auto zoneIdentfierIndex = ipv6HostAddress.indexOf(u'%');
|
||||
// Only perform a minimal sanity check, as at this point the
|
||||
// ipv6HostAddress was already used successfully to establish the connection.
|
||||
if (zoneIdentfierIndex == -1) {
|
||||
return ipv6HostAddress;
|
||||
}
|
||||
|
||||
return ipv6HostAddress.left(zoneIdentfierIndex);
|
||||
}
|
||||
|
||||
void QHttpNetworkConnectionPrivate::prepareRequest(HttpMessagePair &messagePair)
|
||||
{
|
||||
QHttpNetworkRequest &request = messagePair.first;
|
||||
@ -317,7 +329,7 @@ void QHttpNetworkConnectionPrivate::prepareRequest(HttpMessagePair &messagePair)
|
||||
QByteArray host;
|
||||
if (add.setAddress(hostName)) {
|
||||
if (add.protocol() == QAbstractSocket::IPv6Protocol)
|
||||
host = (u'[' + hostName + u']').toLatin1(); //format the ipv6 in the standard way
|
||||
host = (u'[' + removeZoneId(hostName) + u']').toLatin1(); //format the ipv6 in the standard way
|
||||
else
|
||||
host = hostName.toLatin1();
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user