diff --git a/test/jdk/java/net/httpclient/ProxyServer.java b/test/jdk/java/net/httpclient/ProxyServer.java index e07badd2bb7aa..3e3b38909e520 100644 --- a/test/jdk/java/net/httpclient/ProxyServer.java +++ b/test/jdk/java/net/httpclient/ProxyServer.java @@ -195,6 +195,9 @@ class Connection { volatile InputStream clientIn, serverIn; volatile OutputStream clientOut, serverOut; + volatile boolean proxyInClosed; + volatile boolean proxyOutClosed; + final static int CR = 13; final static int LF = 10; @@ -594,9 +597,7 @@ synchronized void proxyCommon(boolean log) throws IOException { if (log) System.out.printf("Proxy Forwarding [request body]: total %d%n", body); } - closing = true; - serverSocket.close(); - clientSocket.close(); + closeClientIn(); } catch (IOException e) { if (!closing && debug) { System.out.println("Proxy: " + e); @@ -615,9 +616,7 @@ synchronized void proxyCommon(boolean log) throws IOException { if (log) System.out.printf("Proxy Forwarding [response]: %s%n", new String(bb, 0, n, UTF_8)); if (log) System.out.printf("Proxy Forwarding [response]: total %d%n", resp); } - closing = true; - serverSocket.close(); - clientSocket.close(); + closeClientOut(); } catch (IOException e) { if (!closing && debug) { System.out.println("Proxy: " + e); @@ -641,6 +640,28 @@ void doTunnel(String dest) throws IOException { proxyCommon(false); } + synchronized void closeClientIn() throws IOException { + closing = true; + proxyInClosed = true; + clientSocket.shutdownInput(); + serverSocket.shutdownOutput(); + if (proxyOutClosed) { + serverSocket.close(); + clientSocket.close(); + } + } + + synchronized void closeClientOut() throws IOException { + closing = true; + proxyOutClosed = true; + serverSocket.shutdownInput(); + clientSocket.shutdownOutput(); + if (proxyInClosed) { + serverSocket.close(); + clientSocket.close(); + } + } + @Override public String toString() { return "Proxy connection " + id + ", client sock:" + clientSocket;