Skip to content

Commit 13d4ddc

Browse files
c-clearydfuch
authored andcommitted
8286962: java/net/httpclient/ServerCloseTest.java failed once with ConnectException
Reviewed-by: dfuchs, jpai
1 parent 6633855 commit 13d4ddc

File tree

1 file changed

+18
-8
lines changed

1 file changed

+18
-8
lines changed

test/jdk/java/net/httpclient/ServerCloseTest.java

+18-8
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2018, 2022, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -287,35 +287,45 @@ public void run() {
287287
try {
288288
while(!stopped) {
289289
Socket clientConnection = ss.accept();
290-
connections.add(clientConnection);
291290
System.out.println(now() + getName() + ": Client accepted");
292291
StringBuilder headers = new StringBuilder();
293-
Socket targetConnection = null;
294292
InputStream ccis = clientConnection.getInputStream();
295293
OutputStream ccos = clientConnection.getOutputStream();
296294
Writer w = new OutputStreamWriter(
297-
clientConnection.getOutputStream(), "UTF-8");
295+
clientConnection.getOutputStream(), UTF_8);
298296
PrintWriter pw = new PrintWriter(w);
299297
System.out.println(now() + getName() + ": Reading request line");
300298
String requestLine = readLine(ccis);
301299
System.out.println(now() + getName() + ": Request line: " + requestLine);
302300

303301
StringTokenizer tokenizer = new StringTokenizer(requestLine);
304302
String method = tokenizer.nextToken();
305-
assert method.equalsIgnoreCase("POST")
306-
|| method.equalsIgnoreCase("GET");
303+
if (!method.equals("GET") && !method.equals("POST")) {
304+
System.err.println(now() + getName() + ": Unexpected request method. Method: " + method);
305+
clientConnection.close();
306+
continue;
307+
}
308+
307309
String path = tokenizer.nextToken();
310+
if (!path.contains("/dummy/x")) {
311+
System.err.println(now() + getName() + ": Unexpected request path. Path: " + path);
312+
clientConnection.close();
313+
continue;
314+
}
315+
308316
URI uri;
309317
try {
310318
String hostport = serverAuthority();
311-
uri = new URI((secure ? "https" : "http") +"://" + hostport + path);
319+
uri = new URI((secure ? "https" : "http") + "://" + hostport + path);
312320
} catch (Throwable x) {
313-
System.err.printf("Bad target address: \"%s\" in \"%s\"%n",
321+
System.err.printf(now() + getName() + ": Bad target address: \"%s\" in \"%s\"%n",
314322
path, requestLine);
315323
clientConnection.close();
316324
continue;
317325
}
318326

327+
// Method, path and URI are valid. Add to connections list
328+
connections.add(clientConnection);
319329
// Read all headers until we find the empty line that
320330
// signals the end of all headers.
321331
String line = requestLine;

0 commit comments

Comments
 (0)