diff options
Diffstat (limited to 'src/network/access/qnetworkcookie.cpp')
-rw-r--r-- | src/network/access/qnetworkcookie.cpp | 36 |
1 files changed, 25 insertions, 11 deletions
diff --git a/src/network/access/qnetworkcookie.cpp b/src/network/access/qnetworkcookie.cpp index a871c04d56..664bc8282c 100644 --- a/src/network/access/qnetworkcookie.cpp +++ b/src/network/access/qnetworkcookie.cpp @@ -51,6 +51,7 @@ #include "QtCore/qstring.h" #include "QtCore/qstringlist.h" #include "QtCore/qurl.h" +#include "QtNetwork/qhostaddress.h" #include "private/qobject_p.h" QT_BEGIN_NAMESPACE @@ -466,12 +467,19 @@ QByteArray QNetworkCookie::toRawForm(RawForm form) const } if (!d->domain.isEmpty()) { result += "; domain="; - QString domainNoDot = d->domain; - if (domainNoDot.startsWith(QLatin1Char('.'))) { + if (d->domain.startsWith(QLatin1Char('.'))) { result += '.'; - domainNoDot = domainNoDot.mid(1); + result += QUrl::toAce(d->domain.mid(1)); + } else { + QHostAddress hostAddr(d->domain); + if (hostAddr.protocol() == QAbstractSocket::IPv6Protocol) { + result += '['; + result += d->domain.toUtf8(); + result += ']'; + } else { + result += QUrl::toAce(d->domain); + } } - result += QUrl::toAce(domainNoDot); } if (!d->path.isEmpty()) { result += "; path="; @@ -1015,14 +1023,20 @@ void QNetworkCookie::normalize(const QUrl &url) d->path = defaultPath; } - if (d->domain.isEmpty()) + if (d->domain.isEmpty()) { d->domain = url.host(); - else if (!d->domain.startsWith(QLatin1Char('.'))) - // Ensure the domain starts with a dot if its field was not empty - // in the HTTP header. There are some servers that forget the - // leading dot and this is actually forbidden according to RFC 2109, - // but all browsers accept it anyway so we do that as well. - d->domain.prepend(QLatin1Char('.')); + } else { + QHostAddress hostAddress(d->domain); + if (hostAddress.protocol() != QAbstractSocket::IPv4Protocol + && hostAddress.protocol() != QAbstractSocket::IPv6Protocol + && !d->domain.startsWith(QLatin1Char('.'))) { + // Ensure the domain starts with a dot if its field was not empty + // in the HTTP header. There are some servers that forget the + // leading dot and this is actually forbidden according to RFC 2109, + // but all browsers accept it anyway so we do that as well. + d->domain.prepend(QLatin1Char('.')); + } + } } #ifndef QT_NO_DEBUG_STREAM |