Skip to content

Commit 5190a96

Browse files
committed
Don't crash if server returns empty response.
1 parent b8f03ca commit 5190a96

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

src/com/codebutler/android_websockets/WebSocketClient.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,9 @@ public void run() {
9494

9595
// Read HTTP response status line.
9696
StatusLine statusLine = parseStatusLine(readLine(stream));
97-
if (statusLine.getStatusCode() != HttpStatus.SC_SWITCHING_PROTOCOLS) {
97+
if (statusLine == null) {
98+
throw new HttpException("Received no reply from server.");
99+
} else if (statusLine.getStatusCode() != HttpStatus.SC_SWITCHING_PROTOCOLS) {
98100
throw new HttpResponseException(statusLine.getStatusCode(), statusLine.getReasonPhrase());
99101
}
100102

@@ -145,6 +147,9 @@ public void send(byte[] data) {
145147
}
146148

147149
private StatusLine parseStatusLine(String line) {
150+
if (TextUtils.isEmpty(line)) {
151+
return null;
152+
}
148153
return BasicLineParser.parseStatusLine(line, new BasicLineParser());
149154
}
150155

0 commit comments

Comments
 (0)