20 * or visit www.oracle.com if you need additional information or have any |
20 * or visit www.oracle.com if you need additional information or have any |
21 * questions. |
21 * questions. |
22 */ |
22 */ |
23 |
23 |
24 import java.io.*; |
24 import java.io.*; |
|
25 import java.net.http.HttpHeaders; |
25 import java.nio.file.Files; |
26 import java.nio.file.Files; |
26 import java.nio.file.Path; |
27 import java.nio.file.Path; |
27 import java.nio.file.Paths; |
28 import java.nio.file.Paths; |
28 |
29 import jdk.internal.net.http.common.HttpHeadersBuilder; |
29 import jdk.internal.net.http.common.HttpHeadersImpl; |
|
30 |
30 |
31 public class Http2EchoHandler implements Http2Handler { |
31 public class Http2EchoHandler implements Http2Handler { |
32 static final Path CWD = Paths.get("."); |
32 static final Path CWD = Paths.get("."); |
33 |
33 |
34 public Http2EchoHandler() {} |
34 public Http2EchoHandler() {} |
38 throws IOException { |
38 throws IOException { |
39 try { |
39 try { |
40 System.err.printf("EchoHandler received request to %s from %s\n", |
40 System.err.printf("EchoHandler received request to %s from %s\n", |
41 t.getRequestURI(), t.getRemoteAddress()); |
41 t.getRequestURI(), t.getRemoteAddress()); |
42 InputStream is = t.getRequestBody(); |
42 InputStream is = t.getRequestBody(); |
43 HttpHeadersImpl map = t.getRequestHeaders(); |
43 HttpHeaders map = t.getRequestHeaders(); |
44 HttpHeadersImpl map1 = t.getResponseHeaders(); |
44 HttpHeadersBuilder headersBuilder = t.getResponseHeaders(); |
45 map1.addHeader("X-Hello", "world"); |
45 headersBuilder.addHeader("X-Hello", "world"); |
46 map1.addHeader("X-Bye", "universe"); |
46 headersBuilder.addHeader("X-Bye", "universe"); |
47 String fixedrequest = map.firstValue("XFixed").orElse(null); |
47 String fixedrequest = map.firstValue("XFixed").orElse(null); |
48 File outfile = Files.createTempFile(CWD, "foo", "bar").toFile(); |
48 File outfile = Files.createTempFile(CWD, "foo", "bar").toFile(); |
49 //System.err.println ("QQQ = " + outfile.toString()); |
49 //System.err.println ("QQQ = " + outfile.toString()); |
50 FileOutputStream fos = new FileOutputStream(outfile); |
50 FileOutputStream fos = new FileOutputStream(outfile); |
51 int count = (int) is.transferTo(fos); |
51 int count = (int) is.transferTo(fos); |