mirror of
https://github.com/pocoproject/poco.git
synced 2025-10-26 18:42:41 +01:00
fixed GH# 172: IPv6 Host field is stripped of Brackets in HTTPClientSession
This commit is contained in:
@@ -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(":");
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user