enable to send cookie

This commit is contained in:
Naoyuki Kanezawa
2013-05-09 02:20:13 +09:00
parent c61f2b9e81
commit 080d4d8935
6 changed files with 59 additions and 0 deletions

View File

@@ -102,6 +102,7 @@ public abstract class Socket extends Emitter {
private String hostname;
private String path;
private String timestampParam;
private String cookie;
private List<String> transports;
private List<String> upgrades;
private Map<String, String> query;
@@ -165,6 +166,7 @@ public abstract class Socket extends Emitter {
this.transports = new ArrayList<String>(Arrays.asList(opts.transports != null ?
opts.transports : new String[]{Polling.NAME, WebSocket.NAME}));
this.policyPort = opts.policyPort != 0 ? opts.policyPort : 843;
this.cookie = opts.cookie;
Socket.sockets.add(this);
Socket.sockets.evs.emit(Sockets.EVENT_ADD, this);
@@ -204,6 +206,7 @@ public abstract class Socket extends Emitter {
opts.timestampRequests = this.timestampRequests;
opts.timestampParam = this.timestampParam;
opts.policyPort = this.policyPort;
opts.cookie = this.cookie;
if (WebSocket.NAME.equals(name)) {
return new WebSocket(opts);

View File

@@ -121,6 +121,11 @@ public abstract class Transport extends Emitter {
public static class Options {
/**
* Cookie value for handshake.
*/
public String cookie;
public String hostname;
public String path;
public String timestampParam;

View File

@@ -17,9 +17,11 @@ public class PollingXHR extends Polling {
private Request sendXhr;
private Request pollXhr;
private String cookie;
public PollingXHR(Options opts) {
super(opts);
this.cookie = opts.cookie;
}
protected Request request() {
@@ -31,6 +33,7 @@ public class PollingXHR extends Polling {
opts = new Request.Options();
}
opts.uri = this.uri();
opts.cookie = this.cookie;
return new Request(opts);
}
@@ -110,12 +113,14 @@ public class PollingXHR extends Polling {
String method;
String uri;
String data;
String cookie;
HttpURLConnection xhr;
public Request(Options opts) {
this.method = opts.method != null ? opts.method : "GET";
this.uri = opts.uri;
this.data = opts.data;
this.cookie = opts.cookie;
}
public void create() {
@@ -134,6 +139,10 @@ public class PollingXHR extends Polling {
xhr.setRequestProperty("Content-type", "text/plain;charset=UTF-8");
}
if (this.cookie != null) {
xhr.setRequestProperty("Cookie", this.cookie);
}
logger.fine(String.format("sending xhr with url %s | data %s", this.uri, this.data));
xhrService.submit(new Runnable() {
@Override
@@ -201,6 +210,7 @@ public class PollingXHR extends Polling {
public String uri;
public String method;
public String data;
public String cookie;
}
}
}