Skip to content

Commit

Permalink
HttpClient tunnel creation assumes when it gets the server response t…
Browse files Browse the repository at this point in the history
…hat the request always sent headers and the headers multimap is never null which leads to an NPE when no headers was sent. - fixes #4074
  • Loading branch information
vietj committed Aug 23, 2021
1 parent 4d408d2 commit 4d1d468
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -744,7 +744,7 @@ private void handleResponseBegin(Stream stream, HttpResponseHead response) {
if ((request.method == HttpMethod.CONNECT &&
response.statusCode == 200) || (
request.method == HttpMethod.GET &&
request.headers.contains("connection", "Upgrade", false) &&
request.headers != null && request.headers.contains("connection", "Upgrade", false) &&
response.statusCode == 101)) {
removeChannelHandlers();
}
Expand Down
28 changes: 28 additions & 0 deletions src/test/java/io/vertx/core/http/HttpTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -5367,6 +5367,34 @@ public void testHttpInvalidConnectResponseChunked() {
await();
}

@Test
public void testUpgradeTunnelNoSwitch() throws Exception {
server.requestHandler(req -> {
HttpServerResponse resp = req.response();
resp.setChunked(true);
resp.write("chunk-1")
.compose(v -> resp.write("chunk-2"))
.compose(v -> resp.end("chunk-3"));
});

startServer();

client.request(HttpMethod.GET, DEFAULT_HTTP_PORT, DEFAULT_HTTP_HOST, "/", onSuccess(req -> {
req.connect(onSuccess(resp -> {
assertEquals(200, resp.statusCode());
List<String> chunks = new ArrayList<>();
resp.handler(chunk -> {
chunks.add(chunk.toString());
});
resp.endHandler(v -> {
assertEquals(Arrays.asList("chunk-1", "chunk-2", "chunk-3"), chunks);
testComplete();
});
}));
}));
await();
}

@Test
public void testEndFromAnotherThread() throws Exception {
waitFor(2);
Expand Down

0 comments on commit 4d1d468

Please sign in to comment.