Skip to content

Commit

Permalink
Merge pull request koush#1 from FilipZawada/master
Browse files Browse the repository at this point in the history
Fixed a bug with incorrect URL when base URI with trailing slash is used.
  • Loading branch information
koush committed Jan 3, 2013
2 parents 7de2163 + 8bce20f commit 9760910
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 @@ -200,7 +200,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 @@ -229,3 +229,4 @@ public void run() {
}.start();
}
}

0 comments on commit 9760910

Please sign in to comment.