Skip to content

Commit

Permalink
Fixed bug with incorrect URL when base URI with trailing slash used.
Browse files Browse the repository at this point in the history
  • Loading branch information
FilipZawada committed May 17, 2012
1 parent 4f49431 commit 8bce20f
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions src/com/codebutler/android_websockets/SocketIOClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,15 @@ public static interface Handler {
public void onError(Exception error);
}

URI mURI;
String mURL;
Handler mHandler;
String mSession;
int mHeartbeat;
int mClosingTimeout;
WebSocketClient mClient;

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

Expand Down Expand Up @@ -86,7 +86,7 @@ public void run() {
}

private void connectSession() throws URISyntaxException {
mClient = new WebSocketClient(new URI(mURI.toString() + "/socket.io/1/websocket/" + mSession), new WebSocketClient.Handler() {
mClient = new WebSocketClient(new URI(mURL + "websocket/" + mSession), new WebSocketClient.Handler() {
@Override
public void onMessage(byte[] data) {
cleanup();
Expand Down Expand Up @@ -195,7 +195,7 @@ public void connect() {
return;
new Thread() {
public void run() {
HttpPost post = new HttpPost(mURI.toString() + "/socket.io/1/");
HttpPost post = new HttpPost(mURL);
try {
String line = downloadUriAsString(post);
String[] parts = line.split(":");
Expand Down Expand Up @@ -224,3 +224,4 @@ public void run() {
}.start();
}
}

0 comments on commit 8bce20f

Please sign in to comment.