Skip to content

Commit

Permalink
8286962: java/net/httpclient/ServerCloseTest.java failed once with Co…
Browse files Browse the repository at this point in the history
…nnectException

Reviewed-by: dfuchs, jpai
  • Loading branch information
c-cleary authored and dfuch committed Jun 15, 2022
1 parent 6633855 commit 13d4ddc
Showing 1 changed file with 18 additions and 8 deletions.
26 changes: 18 additions & 8 deletions test/jdk/java/net/httpclient/ServerCloseTest.java
@@ -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
Expand Down Expand Up @@ -287,35 +287,45 @@ public void run() {
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);
System.out.println(now() + getName() + ": Request line: " + requestLine);

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;
Expand Down

0 comments on commit 13d4ddc

Please sign in to comment.