]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[5620] Http client uses stripped IPv6 address.
authorMarcin Siodelski <marcin@isc.org>
Mon, 14 May 2018 14:59:16 +0000 (16:59 +0200)
committerMarcin Siodelski <marcin@isc.org>
Mon, 14 May 2018 14:59:16 +0000 (16:59 +0200)
src/lib/http/client.cc
src/lib/http/tests/server_client_unittests.cc

index d433136aa34a3d956bcb7dc1b82da3cf73f3d7a1..5b0da858e29a96ac1e05344dcd43e1a4c9ae64cd 100644 (file)
@@ -445,7 +445,8 @@ Connection::doTransaction(const HttpRequestPtr& request,
         /// @todo We're getting a hostname but in fact it is expected to be an IP address.
         /// We should extend the TCPEndpoint to also accept names. Currently, it will fall
         /// over for names.
-        TCPEndpoint endpoint(url_.getHostname(), static_cast<unsigned short>(url_.getPort()));
+        TCPEndpoint endpoint(url_.getStrippedHostname(),
+                             static_cast<unsigned short>(url_.getPort()));
         SocketCallback socket_cb(boost::bind(&Connection::connectCallback, shared_from_this(),
                                              request_timeout, _1));
 
index 8415724ec5954bbb0d170e5fa4de31a8057e4fdc..ebb5e03f50f247d49181860961e05b26f05a6701 100644 (file)
@@ -38,6 +38,9 @@ namespace {
 /// @brief IP address to which HTTP service is bound.
 const std::string SERVER_ADDRESS = "127.0.0.1";
 
+/// @brief IPv6 address to whch HTTP service is bound.
+const std::string IPV6_SERVER_ADDRESS = "::1";
+
 /// @brief Port number to which HTTP service is bound.
 const unsigned short SERVER_PORT = 18123;
 
@@ -507,6 +510,7 @@ TEST_F(HttpListenerTest, listen) {
     io_service_.poll();
 }
 
+
 // This test verifies that persistent HTTP connection can be established when
 // "Conection: Keep-Alive" header value is specified.
 TEST_F(HttpListenerTest, keepAlive) {
@@ -899,7 +903,7 @@ public:
           listener_(io_service_, IOAddress(SERVER_ADDRESS), SERVER_PORT,
                     factory_, HttpListener::RequestTimeout(REQUEST_TIMEOUT),
                     HttpListener::IdleTimeout(IDLE_TIMEOUT)),
-          listener2_(io_service_, IOAddress(SERVER_ADDRESS), SERVER_PORT + 1,
+          listener2_(io_service_, IOAddress(IPV6_SERVER_ADDRESS), SERVER_PORT + 1,
                      factory_, HttpListener::RequestTimeout(REQUEST_TIMEOUT),
                      HttpListener::IdleTimeout(IDLE_TIMEOUT)),
           listener3_(io_service_, IOAddress(SERVER_ADDRESS), SERVER_PORT + 2,
@@ -1036,7 +1040,7 @@ TEST_F(HttpClientTest, multipleDestinations) {
 
     // Specify the URLs on which the servers are available.
     Url url1("http://127.0.0.1:18123");
-    Url url2("http://127.0.0.1:18124");
+    Url url2("http://[::1]:18124");
 
     // Create a request to the first server.
     PostHttpRequestJsonPtr request1 = createRequest("sequence", 1);
@@ -1179,11 +1183,10 @@ TEST_F(HttpClientTest, malformedResponse) {
     // content type.
     PostHttpRequestJsonPtr request = createRequest("requested-content-type", "text/html");
     HttpResponseJsonPtr response(new HttpResponseJson());
-    unsigned resp_num = 0;
     ASSERT_NO_THROW(client.asyncSendRequest(url, request, response,
-        [this, &resp_num](const boost::system::error_code& ec,
-                          const HttpResponsePtr& response,
-                          const std::string& parsing_error) {
+        [this](const boost::system::error_code& ec,
+               const HttpResponsePtr& response,
+               const std::string& parsing_error) {
         io_service_.stop();
         // There should be no IO error (answer from the server is received).
         EXPECT_FALSE(ec);