Issue #6642 - prevent connection close after websocket upgrade

Signed-off-by: Lachlan Roberts <lachlan@webtide.com>
This commit is contained in:
Lachlan Roberts 2021-08-24 19:39:34 +10:00
parent 0fc025d526
commit f7d9d8fcf8
2 changed files with 13 additions and 1 deletions

View File

@ -345,6 +345,18 @@ public class HttpGenerator
return Result.FLUSH; return Result.FLUSH;
} }
// If this is an upgrade then we don't want to close the connection.
if (_info.isResponse() && ((MetaData.Response)_info).getStatus() == HttpStatus.SWITCHING_PROTOCOLS_101)
{
return Result.DONE;
}
else if (_info.isRequest())
{
HttpField connectionHeader = _info.getFields().getField(HttpHeader.CONNECTION);
if (connectionHeader != null && connectionHeader.contains(HttpHeaderValue.UPGRADE.asString()))
return Result.DONE;
}
_state = State.END; _state = State.END;
return Boolean.TRUE.equals(_persistent) ? Result.DONE : Result.SHUTDOWN_OUT; return Boolean.TRUE.equals(_persistent) ? Result.DONE : Result.SHUTDOWN_OUT;
} }

View File

@ -67,7 +67,7 @@ public class ConnectionHeaderTest
} }
@ParameterizedTest @ParameterizedTest
@ValueSource(strings = {"Upgrade", "keep-alive, Upgrade"}) // TODO: should we test "close, Upgrade", what should we expect? @ValueSource(strings = {"Upgrade", "keep-alive, Upgrade", "close, Upgrade"})
public void testConnectionKeepAlive(String connectionHeaderValue) throws Exception public void testConnectionKeepAlive(String connectionHeaderValue) throws Exception
{ {
URI uri = URI.create("ws://localhost:" + connector.getLocalPort() + "/echo"); URI uri = URI.create("ws://localhost:" + connector.getLocalPort() + "/echo");