File tree Expand file tree Collapse file tree 2 files changed +25
-1
lines changed
Expand file tree Collapse file tree 2 files changed +25
-1
lines changed Original file line number Diff line number Diff line change @@ -52,10 +52,11 @@ public class HttpService {
5252 private static String HTTP_SCHEME = "http" ;
5353 private static String HOSTNAME = "localhost" ;
5454 private static String HOSTIP = "127.0.0.1" ;
55+ private static String HOSTIPv6 = "::1" ;
5556
5657 private static final HostnameVerifier HOSTNAME_VERIFIER = new HostnameVerifier () {
5758 public boolean verify (String s , SSLSession sslSession ) {
58- if (s .equals (HOSTNAME ) || s .equals (HOSTIP )) {
59+ if (s .equals (HOSTNAME ) || s .equals (HOSTIP ) || s . equals ( HOSTIPv6 ) ) {
5960 return true ;
6061 } else {
6162 HostnameVerifier hv = HttpsURLConnection .getDefaultHostnameVerifier ();
Original file line number Diff line number Diff line change @@ -41,6 +41,29 @@ public void setUp() throws Exception {
4141 );
4242 }
4343
44+ @ Test
45+ public void testHttpServiceWithHostIP (){
46+ HttpService service = new HttpService ("127.0.0.1" );
47+ ResponseMessage response = service .get ("/" );
48+ Assert .assertEquals (200 , response .getStatus ());
49+ Assert .assertTrue (firstLineIsXmlDtd (response .getContent ()));
50+ }
51+
52+ @ Test
53+ public void testHttpServiceWithHostIPv6 (){
54+ // IPv6 Host without the [] brackets
55+ HttpService service = new HttpService ("::1" );
56+ ResponseMessage response = service .get ("/" );
57+ Assert .assertEquals (200 , response .getStatus ());
58+ Assert .assertTrue (firstLineIsXmlDtd (response .getContent ()));
59+
60+ // IPv6 Host with the [] brackets
61+ HttpService newService = new HttpService ("[::1]" );
62+ ResponseMessage resp = newService .get ("/" );
63+ Assert .assertEquals (200 , resp .getStatus ());
64+ Assert .assertTrue (firstLineIsXmlDtd (resp .getContent ()));
65+ }
66+
4467 @ Test
4568 public void testGet () {
4669 ResponseMessage response = httpService .get ("/" );
You can’t perform that action at this time.
0 commit comments