@@ -1288,39 +1288,46 @@ protected void onHttpHeadersParsed(HttpHeader httpHeader,
1288
1288
return ;
1289
1289
}
1290
1290
}
1291
-
1292
- if (context .currentState != AsyncHandler .STATE .ABORT ) {
1293
- boolean upgrade = context .currentState == AsyncHandler .STATE .UPGRADE ;
1291
+ if (context .isWSRequest ) {
1294
1292
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 ) {
1304
1297
httpHeader .setChunked (false );
1305
- context .protocolHandler .setConnection (ctx .getConnection ());
1306
- DefaultWebSocket ws = new DefaultWebSocket (context .protocolHandler );
1307
1298
ws .onConnect ();
1308
- context .webSocket = new GrizzlyWebSocketAdapter (ws );
1309
1299
WebSocketEngine .getEngine ().setWebSocketHolder (ctx .getConnection (),
1310
1300
context .protocolHandler ,
1311
1301
ws );
1312
1302
((WebSocketUpgradeHandler ) context .handler ).onSuccess (context .webSocket );
1313
1303
final int wsTimeout = context .provider .clientConfig .getWebSocketIdleTimeoutInMs ();
1314
1304
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 );
1319
1309
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 );
1320
1327
} catch (Exception e ) {
1321
1328
httpHeader .setSkipRemainder (true );
1322
1329
context .abort (e );
1323
- }
1330
+ }
1324
1331
}
1325
1332
}
1326
1333
0 commit comments