improve ipv6 support, add tests
This commit is contained in:
@@ -29,23 +29,93 @@ public class SocketTest {
|
||||
assertThat(socket.filterUpgrades(upgrades), is(expected));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void properlyParseHttpUriWithoutPort() throws URISyntaxException {
|
||||
Socket client = new Socket("http://localhost");
|
||||
assertThat(client.hostname, is("localhost"));
|
||||
assertThat(client.port, is(80));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void properlyParseHttpsUriWithoutPort() throws URISyntaxException {
|
||||
Socket client = new Socket("http://localhost");
|
||||
Socket client = new Socket("https://localhost");
|
||||
assertThat(client.hostname, is("localhost"));
|
||||
assertThat(client.port, is(443));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void properlyParseWssUriWithoutPort() throws URISyntaxException {
|
||||
Socket client = new Socket("http://localhost");
|
||||
Socket client = new Socket("wss://localhost");
|
||||
assertThat(client.hostname, is("localhost"));
|
||||
assertThat(client.port, is(443));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void properlyParseWssUriWithPort() throws URISyntaxException {
|
||||
Socket client = new Socket("http://localhost:2020");
|
||||
Socket client = new Socket("wss://localhost:2020");
|
||||
assertThat(client.hostname, is("localhost"));
|
||||
assertThat(client.port, is(2020));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void properlyParseHostWithPort() {
|
||||
Socket.Options opts = new Socket.Options();
|
||||
opts.host = "localhost";
|
||||
opts.port = 8080;
|
||||
Socket client = new Socket(opts);
|
||||
assertThat(client.hostname, is("localhost"));
|
||||
assertThat(client.port, is(8080));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void properlyParseIPv6UriWithoutPort() throws URISyntaxException {
|
||||
Socket client = new Socket("http://[::1]");
|
||||
assertThat(client.hostname, is("::1"));
|
||||
assertThat(client.port, is(80));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void properlyParseIPv6UriWithPort() throws URISyntaxException {
|
||||
Socket client = new Socket("http://[::1]:8080");
|
||||
assertThat(client.hostname, is("::1"));
|
||||
assertThat(client.port, is(8080));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void properlyParseIPv6HostWithoutPort1() {
|
||||
Socket.Options opts = new Socket.Options();
|
||||
opts.host = "[::1]";
|
||||
Socket client = new Socket(opts);
|
||||
assertThat(client.hostname, is("::1"));
|
||||
assertThat(client.port, is(80));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void properlyParseIPv6HostWithoutPort2() {
|
||||
Socket.Options opts = new Socket.Options();
|
||||
opts.secure = true;
|
||||
opts.host = "[::1]";
|
||||
Socket client = new Socket(opts);
|
||||
assertThat(client.hostname, is("::1"));
|
||||
assertThat(client.port, is(443));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void properlyParseIPv6HostWithPort() {
|
||||
Socket.Options opts = new Socket.Options();
|
||||
opts.host = "[::1]";
|
||||
opts.port = 8080;
|
||||
Socket client = new Socket(opts);
|
||||
assertThat(client.hostname, is("::1"));
|
||||
assertThat(client.port, is(8080));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void properlyParseIPv6HostWithoutBrace() {
|
||||
Socket.Options opts = new Socket.Options();
|
||||
opts.host = "::1";
|
||||
Socket client = new Socket(opts);
|
||||
assertThat(client.hostname, is("::1"));
|
||||
assertThat(client.port, is(80));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -87,6 +87,30 @@ public class TransportTest {
|
||||
assertThat(polling.uri().matches("http://localhost/engine.io\\?(j=[0-9]+&)?t=[0-9]+-[0-9]+"), is(true));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void ipv6Uri() {
|
||||
Transport.Options opt = new Transport.Options();
|
||||
opt.path ="/engine.io";
|
||||
opt.hostname = "::1";
|
||||
opt.secure = false;
|
||||
opt.port = 80;
|
||||
opt.timestampRequests = false;
|
||||
Polling polling = new Polling(opt);
|
||||
assertThat(polling.uri(), containsString("http://[::1]/engine.io"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void ipv6UriWithPort() {
|
||||
Transport.Options opt = new Transport.Options();
|
||||
opt.path ="/engine.io";
|
||||
opt.hostname = "::1";
|
||||
opt.secure = false;
|
||||
opt.port = 8080;
|
||||
opt.timestampRequests = false;
|
||||
Polling polling = new Polling(opt);
|
||||
assertThat(polling.uri(), containsString("http://[::1]:8080/engine.io"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void wsUri() {
|
||||
Transport.Options opt = new Transport.Options();
|
||||
@@ -123,6 +147,30 @@ public class TransportTest {
|
||||
assertThat(ws.uri().matches("ws://localhost/engine.io\\?woot=[0-9]+"), is(true));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void wsIPv6Uri() {
|
||||
Transport.Options opt = new Transport.Options();
|
||||
opt.path ="/engine.io";
|
||||
opt.hostname = "::1";
|
||||
opt.secure = false;
|
||||
opt.port = 80;
|
||||
opt.timestampRequests = false;
|
||||
WS ws = new WS(opt);
|
||||
assertThat(ws.uri(), containsString("ws://[::1]/engine.io"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void wsIPv6UriWithPort() {
|
||||
Transport.Options opt = new Transport.Options();
|
||||
opt.path ="/engine.io";
|
||||
opt.hostname = "::1";
|
||||
opt.secure = false;
|
||||
opt.port = 8080;
|
||||
opt.timestampRequests = false;
|
||||
WS ws = new WS(opt);
|
||||
assertThat(ws.uri(), containsString("ws://[::1]:8080/engine.io"));
|
||||
}
|
||||
|
||||
class Polling extends PollingXHR {
|
||||
|
||||
public Polling(Options opts) {
|
||||
|
||||
Reference in New Issue
Block a user