Skip to content

Commit 4c1ecb7

Browse files
committed
Fixed a bug which could not get cookies which have secure attribute when using wss protocol
1 parent 659ee23 commit 4c1ecb7

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

src/android/com/knowledgecode/cordova/websocket/ConnectionTask.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ class ConnectionTask implements Task {
4747
private static final long MAX_CONNECT_TIME = 75000;
4848
private static final int MAX_TEXT_MESSAGE_SIZE = -1;
4949
private static final int MAX_BINARY_MESSAGE_SIZE = -1;
50+
private static final String WSS = "wss";
5051

5152
private final WebSocketClientFactory _factory;
5253
private final SparseArray<Connection> _map;
@@ -73,17 +74,19 @@ public ConnectionTask(WebSocketClientFactory factory, SparseArray<Connection> ma
7374
* Set cookies, if any.
7475
*
7576
* @param cookies
76-
* @param url
77+
* @param host
78+
* @param secure
7779
*/
78-
private static void setCookie(Map<String, String> cookies, String url) {
80+
private static void setCookie(Map<String, String> cookies, String host, String path, boolean secure) {
81+
String url = String.format("%s://%s%s", secure ? "https" : "http", host, path);
7982
String cookie = CookieManager.getInstance().getCookie(url);
8083

8184
if (cookie != null) {
8285
for (String c : cookie.split(";")) {
8386
String[] pair = c.split("=");
8487

8588
if (pair.length == 2) {
86-
cookies.put(pair[0], pair[1]);
89+
cookies.put(pair[0].trim(), pair[1].trim());
8790
}
8891
}
8992
}
@@ -119,7 +122,7 @@ public void execute(String rawArgs, CallbackContext ctx) {
119122
client.getExtensions().add(new PerMessageDeflateExtension());
120123
}
121124

122-
setCookie(client.getCookies(), uri.getHost());
125+
setCookie(client.getCookies(), uri.getHost(), uri.getPath(), WSS.equals(uri.getScheme()));
123126

124127
WebSocketGenerator gen = new WebSocketGenerator(id, ctx);
125128

0 commit comments

Comments
 (0)