send query on connecti
This commit is contained in:
@@ -85,7 +85,12 @@ public class IO {
|
|||||||
io = managers.get(id);
|
io = managers.get(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
return io.socket(parsed.getPath());
|
String query = parsed.getQuery();
|
||||||
|
if (query != null && (opts.query == null || opts.query.isEmpty())) {
|
||||||
|
opts.query = query;
|
||||||
|
}
|
||||||
|
|
||||||
|
return io.socket(parsed.getPath(), opts);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -418,12 +418,13 @@ public class Manager extends Emitter {
|
|||||||
* Initializes {@link Socket} instances for each namespaces.
|
* Initializes {@link Socket} instances for each namespaces.
|
||||||
*
|
*
|
||||||
* @param nsp namespace.
|
* @param nsp namespace.
|
||||||
|
* @param opts options.
|
||||||
* @return a socket instance for the namespace.
|
* @return a socket instance for the namespace.
|
||||||
*/
|
*/
|
||||||
public Socket socket(String nsp) {
|
public Socket socket(String nsp, Options opts) {
|
||||||
Socket socket = this.nsps.get(nsp);
|
Socket socket = this.nsps.get(nsp);
|
||||||
if (socket == null) {
|
if (socket == null) {
|
||||||
socket = new Socket(this, nsp);
|
socket = new Socket(this, nsp, opts);
|
||||||
Socket _socket = this.nsps.putIfAbsent(nsp, socket);
|
Socket _socket = this.nsps.putIfAbsent(nsp, socket);
|
||||||
if (_socket != null) {
|
if (_socket != null) {
|
||||||
socket = _socket;
|
socket = _socket;
|
||||||
@@ -447,6 +448,10 @@ public class Manager extends Emitter {
|
|||||||
return socket;
|
return socket;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Socket socket(String nsp) {
|
||||||
|
return socket(nsp, null);
|
||||||
|
}
|
||||||
|
|
||||||
/*package*/ void destroy(Socket socket) {
|
/*package*/ void destroy(Socket socket) {
|
||||||
this.connecting.remove(socket);
|
this.connecting.remove(socket);
|
||||||
if (!this.connecting.isEmpty()) return;
|
if (!this.connecting.isEmpty()) return;
|
||||||
@@ -458,6 +463,10 @@ public class Manager extends Emitter {
|
|||||||
logger.fine(String.format("writing packet %s", packet));
|
logger.fine(String.format("writing packet %s", packet));
|
||||||
final Manager self = this;
|
final Manager self = this;
|
||||||
|
|
||||||
|
if (packet.query != null && !packet.query.isEmpty() && packet.type == Parser.CONNECT) {
|
||||||
|
packet.nsp += "?" + packet.query;
|
||||||
|
}
|
||||||
|
|
||||||
if (!self.encoding) {
|
if (!self.encoding) {
|
||||||
self.encoding = true;
|
self.encoding = true;
|
||||||
this.encoder.encode(packet, new Parser.Encoder.Callback() {
|
this.encoder.encode(packet, new Parser.Encoder.Callback() {
|
||||||
|
|||||||
@@ -79,6 +79,7 @@ public class Socket extends Emitter {
|
|||||||
}};
|
}};
|
||||||
|
|
||||||
/*package*/ String id;
|
/*package*/ String id;
|
||||||
|
/*package*/ String query;
|
||||||
|
|
||||||
private volatile boolean connected;
|
private volatile boolean connected;
|
||||||
private int ids;
|
private int ids;
|
||||||
@@ -89,9 +90,12 @@ public class Socket extends Emitter {
|
|||||||
private final Queue<List<Object>> receiveBuffer = new LinkedList<List<Object>>();
|
private final Queue<List<Object>> receiveBuffer = new LinkedList<List<Object>>();
|
||||||
private final Queue<Packet<JSONArray>> sendBuffer = new LinkedList<Packet<JSONArray>>();
|
private final Queue<Packet<JSONArray>> sendBuffer = new LinkedList<Packet<JSONArray>>();
|
||||||
|
|
||||||
public Socket(Manager io, String nsp) {
|
public Socket(Manager io, String nsp, Manager.Options opts) {
|
||||||
this.io = io;
|
this.io = io;
|
||||||
this.nsp = nsp;
|
this.nsp = nsp;
|
||||||
|
if (opts != null) {
|
||||||
|
this.query = opts.query;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void subEvents() {
|
private void subEvents() {
|
||||||
@@ -268,7 +272,13 @@ public class Socket extends Emitter {
|
|||||||
logger.fine("transport is open - connecting");
|
logger.fine("transport is open - connecting");
|
||||||
|
|
||||||
if (!"/".equals(this.nsp)) {
|
if (!"/".equals(this.nsp)) {
|
||||||
this.packet(new Packet(Parser.CONNECT));
|
if (this.query != null && !this.query.isEmpty()) {
|
||||||
|
Packet packet = new Packet(Parser.CONNECT);
|
||||||
|
packet.query = this.query;
|
||||||
|
this.packet(packet);
|
||||||
|
} else {
|
||||||
|
this.packet(new Packet(Parser.CONNECT));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ public class Packet<T> {
|
|||||||
public String nsp;
|
public String nsp;
|
||||||
public T data;
|
public T data;
|
||||||
public int attachments;
|
public int attachments;
|
||||||
|
public String query;
|
||||||
|
|
||||||
public Packet() {}
|
public Packet() {}
|
||||||
|
|
||||||
|
|||||||
@@ -168,4 +168,21 @@ public class SocketTest extends Connection {
|
|||||||
|
|
||||||
socket.disconnect();
|
socket.disconnect();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test(timeout = TIMEOUT)
|
||||||
|
public void shouldStoreQueryStringAsAProperty() throws URISyntaxException, InterruptedException {
|
||||||
|
IO.Options opts = new IO.Options();
|
||||||
|
opts.query = "a=b";
|
||||||
|
Socket socket = IO.socket(this.uri() + "/abc", opts);
|
||||||
|
|
||||||
|
Socket socket2 = IO.socket(this.uri() + "/abc?b=c&d=e");
|
||||||
|
|
||||||
|
IO.Options opts3 = new IO.Options();
|
||||||
|
opts.query = "%26a=%26%3D%3Fa";
|
||||||
|
Socket socket3 = IO.socket(this.uri() + "/abc", opts);
|
||||||
|
|
||||||
|
assertThat(socket.query, is("a=b"));
|
||||||
|
assertThat(socket2.query, is("b=c&d=e"));
|
||||||
|
assertThat(socket3.query, is("%26a=%26%3D%3Fa"));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user