Skip to content

Commit 8bce20f

Browse files
committed
Fixed bug with incorrect URL when base URI with trailing slash used.
1 parent 4f49431 commit 8bce20f

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

src/com/codebutler/android_websockets/SocketIOClient.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,15 @@ public static interface Handler {
3030
public void onError(Exception error);
3131
}
3232

33-
URI mURI;
33+
String mURL;
3434
Handler mHandler;
3535
String mSession;
3636
int mHeartbeat;
37-
int mClosingTimeout;
3837
WebSocketClient mClient;
3938

4039
public SocketIOClient(URI uri, Handler handler) {
41-
mURI = uri;
40+
// remove trailing "/" from URI, in case user provided e.g. http://test.com/
41+
mURL = uri.toString().replaceAll("/$", "") + "/socket.io/1/";
4242
mHandler = handler;
4343
}
4444

@@ -86,7 +86,7 @@ public void run() {
8686
}
8787

8888
private void connectSession() throws URISyntaxException {
89-
mClient = new WebSocketClient(new URI(mURI.toString() + "/socket.io/1/websocket/" + mSession), new WebSocketClient.Handler() {
89+
mClient = new WebSocketClient(new URI(mURL + "websocket/" + mSession), new WebSocketClient.Handler() {
9090
@Override
9191
public void onMessage(byte[] data) {
9292
cleanup();
@@ -195,7 +195,7 @@ public void connect() {
195195
return;
196196
new Thread() {
197197
public void run() {
198-
HttpPost post = new HttpPost(mURI.toString() + "/socket.io/1/");
198+
HttpPost post = new HttpPost(mURL);
199199
try {
200200
String line = downloadUriAsString(post);
201201
String[] parts = line.split(":");
@@ -224,3 +224,4 @@ public void run() {
224224
}.start();
225225
}
226226
}
227+

0 commit comments

Comments
 (0)