@@ -448,6 +448,41 @@ TEST_FIXTURE(uri_address, test_leaks)
448
448
listener.close ().wait ();
449
449
}
450
450
451
+ TEST_FIXTURE (uri_address, remote_address)
452
+ {
453
+ http_listener listener (U (" http://localhost:45678/path1" ));
454
+ listener.open ().wait ();
455
+
456
+ test_http_client::scoped_client client (U (" http://localhost:45678" ));
457
+ test_http_client * p_client = client.client ();
458
+
459
+ volatile unsigned long requestCount = 0 ;
460
+
461
+ listener.support (methods::GET, [&requestCount](http_request request)
462
+ {
463
+ const string_t & remoteAddr = request.get_remote_address ();
464
+ const string_t & localhost4 = string_t (U (" 127.0.0.1" ));
465
+ const string_t & localhost6 = string_t (U (" ::1" ));
466
+
467
+ // We can't guarantee that the host has both IPv4 and IPv6 available, so check for either IP
468
+ VERIFY_IS_TRUE ((remoteAddr == localhost4) || (remoteAddr == localhost6));
469
+
470
+ os_utilities::interlocked_increment (&requestCount);
471
+ request.reply (status_codes::NoContent);
472
+ });
473
+
474
+ // Send a request to the listener
475
+ VERIFY_ARE_EQUAL (0 , p_client->request (methods::GET, U (" /path1" )));
476
+
477
+ p_client->next_response ().then ([](test_response *p_response)
478
+ {
479
+ http_asserts::assert_test_response_equals (p_response, status_codes::NoContent);
480
+ }).wait ();
481
+
482
+ VERIFY_IS_TRUE (requestCount >= 1 );
483
+ listener.close ().wait ();
484
+ }
485
+
451
486
}
452
487
453
488
}}}}
0 commit comments