Skip to content

Commit 45ce97b

Browse files
committed
Fix for the Grizzly side of AsyncHttpClient#101 : [websocket] onError must not be called when status code is != 101.
1 parent 44fb654 commit 45ce97b

File tree

1 file changed

+27
-20
lines changed

1 file changed

+27
-20
lines changed

src/main/java/com/ning/http/client/providers/grizzly/GrizzlyAsyncHttpProvider.java

Lines changed: 27 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1288,39 +1288,46 @@ protected void onHttpHeadersParsed(HttpHeader httpHeader,
12881288
return;
12891289
}
12901290
}
1291-
1292-
if (context.currentState != AsyncHandler.STATE.ABORT) {
1293-
boolean upgrade = context.currentState == AsyncHandler.STATE.UPGRADE;
1291+
if (context.isWSRequest) {
12941292
try {
1295-
context.currentState = handler.onHeadersReceived(
1296-
responseHeaders);
1297-
} catch (Exception e) {
1298-
httpHeader.setSkipRemainder(true);
1299-
context.abort(e);
1300-
return;
1301-
}
1302-
if (upgrade) {
1303-
try {
1293+
context.protocolHandler.setConnection(ctx.getConnection());
1294+
DefaultWebSocket ws = new DefaultWebSocket(context.protocolHandler);
1295+
context.webSocket = new GrizzlyWebSocketAdapter(ws);
1296+
if (context.currentState == AsyncHandler.STATE.UPGRADE) {
13041297
httpHeader.setChunked(false);
1305-
context.protocolHandler.setConnection(ctx.getConnection());
1306-
DefaultWebSocket ws = new DefaultWebSocket(context.protocolHandler);
13071298
ws.onConnect();
1308-
context.webSocket = new GrizzlyWebSocketAdapter(ws);
13091299
WebSocketEngine.getEngine().setWebSocketHolder(ctx.getConnection(),
13101300
context.protocolHandler,
13111301
ws);
13121302
((WebSocketUpgradeHandler) context.handler).onSuccess(context.webSocket);
13131303
final int wsTimeout = context.provider.clientConfig.getWebSocketIdleTimeoutInMs();
13141304
IdleTimeoutFilter.setCustomTimeout(ctx.getConnection(),
1315-
((wsTimeout <= 0)
1316-
? IdleTimeoutFilter.FOREVER
1317-
: wsTimeout),
1318-
TimeUnit.MILLISECONDS);
1305+
((wsTimeout <= 0)
1306+
? IdleTimeoutFilter.FOREVER
1307+
: wsTimeout),
1308+
TimeUnit.MILLISECONDS);
13191309
context.result(handler.onCompleted());
1310+
} else {
1311+
httpHeader.setSkipRemainder(true);
1312+
((WebSocketUpgradeHandler) context.handler).
1313+
onClose(context.webSocket,
1314+
1002,
1315+
"WebSocket protocol error: unexpected HTTP response status during handshake.");
1316+
context.result(null);
1317+
}
1318+
} catch (Exception e) {
1319+
httpHeader.setSkipRemainder(true);
1320+
context.abort(e);
1321+
}
1322+
} else {
1323+
if (context.currentState != AsyncHandler.STATE.ABORT) {
1324+
try {
1325+
context.currentState = handler.onHeadersReceived(
1326+
responseHeaders);
13201327
} catch (Exception e) {
13211328
httpHeader.setSkipRemainder(true);
13221329
context.abort(e);
1323-
}
1330+
}
13241331
}
13251332
}
13261333

0 commit comments

Comments
 (0)