Skip to content

Commit

Permalink
Issue #6642 - prevent connection close after websocket upgrade
Browse files Browse the repository at this point in the history
Signed-off-by: Lachlan Roberts <lachlan@webtide.com>
  • Loading branch information
lachlan-roberts committed Aug 24, 2021
1 parent 0fc025d commit f7d9d8f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
12 changes: 12 additions & 0 deletions jetty-http/src/main/java/org/eclipse/jetty/http/HttpGenerator.java
Expand Up @@ -345,6 +345,18 @@ private Result completing(ByteBuffer chunk, ByteBuffer content)
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;
return Boolean.TRUE.equals(_persistent) ? Result.DONE : Result.SHUTDOWN_OUT;
}
Expand Down
Expand Up @@ -67,7 +67,7 @@ public static void stopContainers() throws Exception
}

@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
{
URI uri = URI.create("ws://localhost:" + connector.getLocalPort() + "/echo");
Expand Down

0 comments on commit f7d9d8f

Please sign in to comment.