31 * @modules java.base/sun.net.www.http |
31 * @modules java.base/sun.net.www.http |
32 * java.net.http/jdk.internal.net.http.common |
32 * java.net.http/jdk.internal.net.http.common |
33 * java.net.http/jdk.internal.net.http.frame |
33 * java.net.http/jdk.internal.net.http.frame |
34 * java.net.http/jdk.internal.net.http.hpack |
34 * java.net.http/jdk.internal.net.http.hpack |
35 * @run testng/othervm |
35 * @run testng/othervm |
36 * -Djdk.httpclient.HttpClient.log=headers EncodedCharsInURI |
36 * -Djdk.internal.httpclient.debug=true |
|
37 * -Djdk.httpclient.HttpClient.log=headers,errors EncodedCharsInURI |
37 */ |
38 */ |
38 //* -Djdk.internal.httpclient.debug=true |
39 //* -Djdk.internal.httpclient.debug=true |
39 |
40 |
40 import com.sun.net.httpserver.HttpServer; |
41 import com.sun.net.httpserver.HttpServer; |
41 import com.sun.net.httpserver.HttpsConfigurator; |
42 import com.sun.net.httpserver.HttpsConfigurator; |
46 import org.testng.annotations.BeforeTest; |
47 import org.testng.annotations.BeforeTest; |
47 import org.testng.annotations.DataProvider; |
48 import org.testng.annotations.DataProvider; |
48 import org.testng.annotations.Test; |
49 import org.testng.annotations.Test; |
49 |
50 |
50 import javax.net.ServerSocketFactory; |
51 import javax.net.ServerSocketFactory; |
51 import javax.net.SocketFactory; |
|
52 import javax.net.ssl.SSLContext; |
52 import javax.net.ssl.SSLContext; |
53 import javax.net.ssl.SSLServerSocket; |
|
54 import javax.net.ssl.SSLServerSocketFactory; |
|
55 import java.io.IOException; |
53 import java.io.IOException; |
56 import java.io.InputStream; |
54 import java.io.InputStream; |
57 import java.io.OutputStream; |
55 import java.io.OutputStream; |
58 import java.io.OutputStreamWriter; |
|
59 import java.io.PrintWriter; |
|
60 import java.io.Writer; |
|
61 import java.net.InetAddress; |
56 import java.net.InetAddress; |
62 import java.net.InetSocketAddress; |
57 import java.net.InetSocketAddress; |
63 import java.net.ServerSocket; |
58 import java.net.ServerSocket; |
64 import java.net.Socket; |
59 import java.net.Socket; |
65 import java.net.SocketAddress; |
|
66 import java.net.URI; |
60 import java.net.URI; |
67 import java.net.http.HttpClient; |
61 import java.net.http.HttpClient; |
68 import java.net.http.HttpRequest; |
62 import java.net.http.HttpRequest; |
69 import java.net.http.HttpRequest.BodyPublisher; |
63 import java.net.http.HttpRequest.BodyPublisher; |
70 import java.net.http.HttpRequest.BodyPublishers; |
64 import java.net.http.HttpRequest.BodyPublishers; |
71 import java.net.http.HttpResponse; |
65 import java.net.http.HttpResponse; |
72 import java.net.http.HttpResponse.BodyHandler; |
66 import java.net.http.HttpResponse.BodyHandler; |
73 import java.net.http.HttpResponse.BodyHandlers; |
67 import java.net.http.HttpResponse.BodyHandlers; |
74 import java.nio.file.Path; |
|
75 import java.nio.file.Paths; |
|
76 import java.util.List; |
68 import java.util.List; |
77 import java.util.Locale; |
69 import java.util.Locale; |
78 import java.util.StringTokenizer; |
70 import java.util.StringTokenizer; |
79 import java.util.concurrent.CompletableFuture; |
71 import java.util.concurrent.CompletableFuture; |
80 import java.util.concurrent.ConcurrentHashMap; |
72 import java.util.concurrent.ConcurrentHashMap; |
85 import java.util.concurrent.atomic.AtomicLong; |
77 import java.util.concurrent.atomic.AtomicLong; |
86 |
78 |
87 import static java.lang.String.format; |
79 import static java.lang.String.format; |
88 import static java.lang.System.in; |
80 import static java.lang.System.in; |
89 import static java.lang.System.out; |
81 import static java.lang.System.out; |
|
82 import static java.nio.charset.StandardCharsets.US_ASCII; |
90 import static java.nio.charset.StandardCharsets.UTF_8; |
83 import static java.nio.charset.StandardCharsets.UTF_8; |
91 import static java.net.http.HttpClient.Builder.NO_PROXY; |
84 import static java.net.http.HttpClient.Builder.NO_PROXY; |
92 import static org.testng.Assert.assertEquals; |
85 import static org.testng.Assert.assertEquals; |
93 import static org.testng.Assert.assertTrue; |
86 import static org.testng.Assert.assertTrue; |
94 |
87 |
400 System.out.println(now() + getName() + ": Client accepted"); |
393 System.out.println(now() + getName() + ": Client accepted"); |
401 StringBuilder headers = new StringBuilder(); |
394 StringBuilder headers = new StringBuilder(); |
402 Socket targetConnection = null; |
395 Socket targetConnection = null; |
403 InputStream ccis = clientConnection.getInputStream(); |
396 InputStream ccis = clientConnection.getInputStream(); |
404 OutputStream ccos = clientConnection.getOutputStream(); |
397 OutputStream ccos = clientConnection.getOutputStream(); |
405 Writer w = new OutputStreamWriter( |
|
406 clientConnection.getOutputStream(), "UTF-8"); |
|
407 PrintWriter pw = new PrintWriter(w); |
|
408 System.out.println(now() + getName() + ": Reading request line"); |
398 System.out.println(now() + getName() + ": Reading request line"); |
409 String requestLine = readLine(ccis); |
399 String requestLine = readLine(ccis); |
410 System.out.println(now() + getName() + ": Request line: " + requestLine); |
400 System.out.println(now() + getName() + ": Request line: " + requestLine); |
411 |
401 |
412 StringTokenizer tokenizer = new StringTokenizer(requestLine); |
402 StringTokenizer tokenizer = new StringTokenizer(requestLine); |
457 .append("\r\n\r\n"); |
447 .append("\r\n\r\n"); |
458 |
448 |
459 // Then send the 200 OK response to the client |
449 // Then send the 200 OK response to the client |
460 System.out.println(now() + getName() + ": Sending " |
450 System.out.println(now() + getName() + ": Sending " |
461 + response); |
451 + response); |
462 pw.print(response); |
452 ccos.write(response.toString().getBytes(UTF_8)); |
463 pw.flush(); |
453 ccos.flush(); |
|
454 System.out.println(now() + getName() + ": sent response headers"); |
464 ccos.write(b); |
455 ccos.write(b); |
465 ccos.flush(); |
456 ccos.flush(); |
466 ccos.close(); |
457 ccos.close(); |
|
458 System.out.println(now() + getName() + ": sent " + b.length + " body bytes"); |
467 connections.remove(clientConnection); |
459 connections.remove(clientConnection); |
468 clientConnection.close(); |
460 clientConnection.close(); |
469 } |
461 } |
470 } catch (Throwable t) { |
462 } catch (Throwable t) { |
471 if (!stopped) { |
463 if (!stopped) { |