Skip to content

Commit

Permalink
Backport cddaf686e16424e9543be50a48b1c02337e79cf1
Browse files Browse the repository at this point in the history
  • Loading branch information
duke committed Aug 3, 2024
1 parent 7f8fdbd commit 5df169e
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions test/jdk/sun/net/www/http/KeepAliveCache/B5045306.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@

import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.OutputStream;
import java.lang.management.ManagementFactory;
import java.lang.management.ThreadInfo;
import java.lang.management.ThreadMXBean;
Expand All @@ -40,7 +40,6 @@
import java.net.InetSocketAddress;
import java.net.Proxy;
import java.net.URL;
import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.Executors;
Expand Down Expand Up @@ -176,9 +175,9 @@ public void handle(HttpExchange trans) {
byte[] responseBody = new byte[RESPONSE_DATA_LENGTH];
for (int i=0; i<responseBody.length; i++)
responseBody[i] = 0x41;
trans.sendResponseHeaders(200, 0);
try(PrintWriter pw = new PrintWriter(trans.getResponseBody(), false, Charset.forName("UTF-8"))) {
pw.print(responseBody);
trans.sendResponseHeaders(200, responseBody.length);
try (OutputStream os = trans.getResponseBody()) {
os.write(responseBody);
}
} else if (path.equals("/secondCall")) {
int port2 = trans.getLocalAddress().getPort();
Expand All @@ -201,10 +200,10 @@ public void handle(HttpExchange trans) {
responseBody[i] = 0x41;
// override the Content-length header to be greater than the actual response body
trans.sendResponseHeaders(200, responseBody.length+1);
try(PrintWriter pw = new PrintWriter(trans.getResponseBody(), false, Charset.forName("UTF-8"))) {
pw.print(responseBody);
}
OutputStream os = trans.getResponseBody();
os.write(responseBody);
// now close the socket
// closing the stream here would throw; close the exchange instead
trans.close();
}
} catch (Exception e) {
Expand Down

0 comments on commit 5df169e

Please sign in to comment.