Skip to content

Commit

Permalink
ProxyServer-8338740
Browse files Browse the repository at this point in the history
  • Loading branch information
dfuch committed Aug 22, 2024
1 parent 01d03e0 commit 5cbc473
Showing 1 changed file with 27 additions and 6 deletions.
33 changes: 27 additions & 6 deletions test/jdk/java/net/httpclient/ProxyServer.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -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;
Expand Down

0 comments on commit 5cbc473

Please sign in to comment.