fix "Host" header of ipv6 URLs in QNAM

Change-Id: I6bf3320e5ab285e3d1f4d72bd1ef0a0e42813e5b
Reviewed-on: http://codereview.qt.nokia.com/115
Reviewed-by: Markus Goetz
bb10
shiroki 2011-05-25 11:11:51 +02:00 committed by Qt Continuous Integration System
parent 56f030b994
commit a78e184811
2 changed files with 20 additions and 10 deletions

View File

@ -261,7 +261,17 @@ void QHttpNetworkConnectionPrivate::prepareRequest(HttpMessagePair &messagePair)
// set the host
value = request.headerField("host");
if (value.isEmpty()) {
QByteArray host = QUrl::toAce(hostName);
QHostAddress add;
QByteArray host;
if (add.setAddress(hostName)) {
if (add.protocol() == QAbstractSocket::IPv6Protocol)
host = "[" + hostName.toAscii() + "]";//format the ipv6 in the standard way
else
host = hostName.toAscii();
} else {
host = QUrl::toAce(hostName);
}
int port = request.url().port();
if (port != -1) {

View File

@ -457,9 +457,9 @@ public:
: client(0), dataToTransmit(data), doClose(true), doSsl(ssl), ipv6(useipv6),
multiple(false), totalConnections(0)
{
if( useipv6 ){
if (useipv6) {
listen(QHostAddress::AnyIPv6);
}else{
} else {
listen();
}
if (thread) {
@ -2338,8 +2338,9 @@ void tst_QNetworkReply::connectToIPv6Address_data()
QTest::addColumn<QUrl>("url");
QTest::addColumn<QNetworkReply::NetworkError>("error");
QTest::addColumn<QByteArray>("dataToSend");
QTest::addColumn<QByteArray>("serverVerifyData");
QTest::newRow("localhost") << QUrl(QByteArray("http://[::1]")) << QNetworkReply::NoError<< QByteArray("localhost") << QByteArray("\r\nHost: [::1]\r\n");
QTest::addColumn<QByteArray>("hostfield");
QTest::newRow("localhost") << QUrl(QByteArray("http://[::1]")) << QNetworkReply::NoError<< QByteArray("localhost") << QByteArray("[::1]");
//QTest::newRow("ipv4localhost") << QUrl(QByteArray("http://127.0.0.1")) << QNetworkReply::NoError<< QByteArray("ipv4localhost") << QByteArray("127.0.0.1");
//to add more test data here
}
@ -2348,7 +2349,7 @@ void tst_QNetworkReply::connectToIPv6Address()
QFETCH(QUrl, url);
QFETCH(QNetworkReply::NetworkError, error);
QFETCH(QByteArray, dataToSend);
QFETCH(QByteArray, serverVerifyData);
QFETCH(QByteArray, hostfield);
QByteArray httpResponse = QByteArray("HTTP/1.0 200 OK\r\nContent-Length: ");
httpResponse += QByteArray::number(dataToSend.size());
@ -2366,10 +2367,9 @@ void tst_QNetworkReply::connectToIPv6Address()
QTestEventLoop::instance().enterLoop(10);
QVERIFY(!QTestEventLoop::instance().timeout());
QByteArray content = reply->readAll();
if( !serverVerifyData.isEmpty()){
//qDebug() << server.receivedData;
//QVERIFY(server.receivedData.contains(serverVerifyData)); //got a bug here
}
//qDebug() << server.receivedData;
QByteArray hostinfo = "\r\nHost: " + hostfield + ":" + QByteArray::number(server.serverPort()) + "\r\n";
QVERIFY(server.receivedData.contains(hostinfo));
QVERIFY(content == dataToSend);
QCOMPARE(reply->url(), request.url());
QVERIFY(reply->error() == error);