diff --git a/Net/src/HTTPRequest.cpp b/Net/src/HTTPRequest.cpp index f3fa6d1bc..cd86f5aac 100644 --- a/Net/src/HTTPRequest.cpp +++ b/Net/src/HTTPRequest.cpp @@ -118,7 +118,19 @@ void HTTPRequest::setHost(const std::string& host) void HTTPRequest::setHost(const std::string& host, Poco::UInt16 port) { - std::string value(host); + std::string value; + if (host.find(':') != std::string::npos) + { + // IPv6 address + value.append("["); + value.append(host); + value.append("]"); + } + else + { + value.append(host); + } + if (port != 80 && port != 443) { value.append(":"); diff --git a/Net/testsuite/src/HTTPRequestTest.cpp b/Net/testsuite/src/HTTPRequestTest.cpp index 40cc40feb..30ad5b2c1 100644 --- a/Net/testsuite/src/HTTPRequestTest.cpp +++ b/Net/testsuite/src/HTTPRequestTest.cpp @@ -1,7 +1,7 @@ // // HTTPRequestTest.cpp // -// $Id: //poco/1.4/Net/testsuite/src/HTTPRequestTest.cpp#3 $ +// $Id: //poco/1.4/Net/testsuite/src/HTTPRequestTest.cpp#4 $ // // Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH. // and Contributors. @@ -73,7 +73,7 @@ void HTTPRequestTest::testWrite2() std::ostringstream ostr; request.write(ostr); std::string s = ostr.str(); - assert (s == "HEAD /index.html HTTP/1.1\r\nHost: localhost\r\nConnection: Keep-Alive\r\nUser-Agent: Poco\r\n\r\n"); + assert (s == "HEAD /index.html HTTP/1.1\r\nConnection: Keep-Alive\r\nHost: localhost\r\nUser-Agent: Poco\r\n\r\n"); } @@ -88,7 +88,20 @@ void HTTPRequestTest::testWrite3() std::ostringstream ostr; request.write(ostr); std::string s = ostr.str(); - assert (s == "POST /test.cgi HTTP/1.1\r\nHost: localhost:8000\r\nConnection: Close\r\nUser-Agent: Poco\r\nContent-Length: 100\r\nContent-Type: text/plain\r\n\r\n"); + assert (s == "POST /test.cgi HTTP/1.1\r\nConnection: Close\r\nContent-Length: 100\r\nContent-Type: text/plain\r\nHost: localhost:8000\r\nUser-Agent: Poco\r\n\r\n"); +} + + +void HTTPRequestTest::testWrite4() +{ + HTTPRequest request(HTTPRequest::HTTP_HEAD, "/index.html", HTTPMessage::HTTP_1_1); + request.setHost("fe80::1", 88); + request.setKeepAlive(true); + request.set("User-Agent", "Poco"); + std::ostringstream ostr; + request.write(ostr); + std::string s = ostr.str(); + assert (s == "HEAD /index.html HTTP/1.1\r\nConnection: Keep-Alive\r\nHost: [fe80::1]:88\r\nUser-Agent: Poco\r\n\r\n"); } @@ -262,6 +275,7 @@ CppUnit::Test* HTTPRequestTest::suite() CppUnit_addTest(pSuite, HTTPRequestTest, testWrite1); CppUnit_addTest(pSuite, HTTPRequestTest, testWrite2); CppUnit_addTest(pSuite, HTTPRequestTest, testWrite3); + CppUnit_addTest(pSuite, HTTPRequestTest, testWrite4); CppUnit_addTest(pSuite, HTTPRequestTest, testRead1); CppUnit_addTest(pSuite, HTTPRequestTest, testRead2); CppUnit_addTest(pSuite, HTTPRequestTest, testRead3); diff --git a/Net/testsuite/src/HTTPRequestTest.h b/Net/testsuite/src/HTTPRequestTest.h index 66bffa2d7..3578f0cdb 100644 --- a/Net/testsuite/src/HTTPRequestTest.h +++ b/Net/testsuite/src/HTTPRequestTest.h @@ -1,7 +1,7 @@ // // HTTPRequestTest.h // -// $Id: //poco/1.4/Net/testsuite/src/HTTPRequestTest.h#2 $ +// $Id: //poco/1.4/Net/testsuite/src/HTTPRequestTest.h#3 $ // // Definition of the HTTPRequestTest class. // @@ -49,6 +49,7 @@ public: void testWrite1(); void testWrite2(); void testWrite3(); + void testWrite4(); void testRead1(); void testRead2(); void testRead3();