8286962: java/net/httpclient/ServerCloseTest.java failed once with ConnectException

Reviewed-by: dfuchs, jpai
This commit is contained in:
Conor Cleary 2022-06-15 15:41:18 +00:00 committed by Daniel Fuchs
parent 6633855ca7
commit 13d4ddc35b

@ -1,5 +1,5 @@
/*
* Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2018, 2022, 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
@ -287,14 +287,12 @@ public class ServerCloseTest implements HttpServerAdapters {
try {
while(!stopped) {
Socket clientConnection = ss.accept();
connections.add(clientConnection);
System.out.println(now() + getName() + ": Client accepted");
StringBuilder headers = new StringBuilder();
Socket targetConnection = null;
InputStream ccis = clientConnection.getInputStream();
OutputStream ccos = clientConnection.getOutputStream();
Writer w = new OutputStreamWriter(
clientConnection.getOutputStream(), "UTF-8");
clientConnection.getOutputStream(), UTF_8);
PrintWriter pw = new PrintWriter(w);
System.out.println(now() + getName() + ": Reading request line");
String requestLine = readLine(ccis);
@ -302,20 +300,32 @@ public class ServerCloseTest implements HttpServerAdapters {
StringTokenizer tokenizer = new StringTokenizer(requestLine);
String method = tokenizer.nextToken();
assert method.equalsIgnoreCase("POST")
|| method.equalsIgnoreCase("GET");
if (!method.equals("GET") && !method.equals("POST")) {
System.err.println(now() + getName() + ": Unexpected request method. Method: " + method);
clientConnection.close();
continue;
}
String path = tokenizer.nextToken();
if (!path.contains("/dummy/x")) {
System.err.println(now() + getName() + ": Unexpected request path. Path: " + path);
clientConnection.close();
continue;
}
URI uri;
try {
String hostport = serverAuthority();
uri = new URI((secure ? "https" : "http") +"://" + hostport + path);
uri = new URI((secure ? "https" : "http") + "://" + hostport + path);
} catch (Throwable x) {
System.err.printf("Bad target address: \"%s\" in \"%s\"%n",
System.err.printf(now() + getName() + ": Bad target address: \"%s\" in \"%s\"%n",
path, requestLine);
clientConnection.close();
continue;
}
// Method, path and URI are valid. Add to connections list
connections.add(clientConnection);
// Read all headers until we find the empty line that
// signals the end of all headers.
String line = requestLine;