diff --git a/test/jdk/java/net/httpclient/ServerCloseTest.java b/test/jdk/java/net/httpclient/ServerCloseTest.java index aa1ca9dcaad..5bb040de825 100644 --- a/test/jdk/java/net/httpclient/ServerCloseTest.java +++ b/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 @@ -287,14 +287,12 @@ 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); @@ -302,20 +300,32 @@ public void run() { 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;