Skip to content
Permalink
Browse files

8240666: Websocket client’s OpeningHandshake discards the HTTP respon…

…se body

The fix updates jdk.internal.net.http.websocket. OpeningHandshake.send() method to process the response body from server

Reviewed-by: chegar, dfuchs, prappo
  • Loading branch information
rhyadav authored and Julia Boes committed May 6, 2020
1 parent 9f86d94 commit ed24927500ed3bb95da6e1c4140331d5f5ccac3e
@@ -188,7 +188,7 @@ static URI createRequestURI(URI uri) {

public CompletableFuture<Result> send() {
PrivilegedAction<CompletableFuture<Result>> pa = () ->
client.sendAsync(this.request, BodyHandlers.discarding())
client.sendAsync(this.request, BodyHandlers.ofString())
.thenCompose(this::resultFrom);
return AccessController.doPrivileged(pa);
}
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2017, 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2017, 2020, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -23,6 +23,7 @@

/*
* @test
* @bug 8240666
* @summary Basic test for WebSocketHandshakeException
* @library /test/lib
* @build jdk.test.lib.net.SimpleSSLContext
@@ -55,7 +56,9 @@
import static java.net.http.HttpClient.Builder.NO_PROXY;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertNotNull;
import static org.testng.Assert.assertTrue;
import static org.testng.Assert.fail;
import static java.lang.System.out;

public class WSHandshakeExceptionTest {

@@ -107,6 +110,9 @@ public void test(String uri, boolean sameClient) {
}
WebSocketHandshakeException wse = (WebSocketHandshakeException) t;
assertNotNull(wse.getResponse());
out.println("Status code is " + wse.getResponse().statusCode());
out.println("Response is " + wse.getResponse().body());
assertTrue(((String)wse.getResponse().body()).contains("404"));
assertEquals(wse.getResponse().statusCode(), 404);
}
}

0 comments on commit ed24927

Please sign in to comment.
You can’t perform that action at this time.