1 /* |
1 /* |
2 * Copyright (c) 2016, 2018, Oracle and/or its affiliates. All rights reserved. |
2 * Copyright (c) 2016, 2019, Oracle and/or its affiliates. All rights reserved. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * |
4 * |
5 * This code is free software; you can redistribute it and/or modify it |
5 * This code is free software; you can redistribute it and/or modify it |
6 * under the terms of the GNU General Public License version 2 only, as |
6 * under the terms of the GNU General Public License version 2 only, as |
7 * published by the Free Software Foundation. |
7 * published by the Free Software Foundation. |
40 examineExchange(t); |
40 examineExchange(t); |
41 try (InputStream is = t.getRequestBody()) { |
41 try (InputStream is = t.getRequestBody()) { |
42 is.readAllBytes(); |
42 is.readAllBytes(); |
43 String location = supplier.get(); |
43 String location = supplier.get(); |
44 System.err.printf("RedirectHandler request to %s from %s\n", |
44 System.err.printf("RedirectHandler request to %s from %s\n", |
45 t.getRequestURI().toString(), t.getRemoteAddress().toString()); |
45 t.getRequestURI().toString(), t.getRemoteAddress().toString()); |
46 System.err.println("Redirecting to: " + location); |
46 System.err.println("Redirecting to: " + location); |
47 HttpHeadersBuilder headersBuilder = t.getResponseHeaders(); |
47 HttpHeadersBuilder headersBuilder = t.getResponseHeaders(); |
48 headersBuilder.addHeader("Location", location); |
48 headersBuilder.addHeader("Location", location); |
49 t.sendResponseHeaders(301, 1024); |
49 t.sendResponseHeaders(redirectCode(), 1024); |
50 byte[] bb = new byte[1024]; |
50 byte[] bb = new byte[1024]; |
51 OutputStream os = t.getResponseBody(); |
51 OutputStream os = t.getResponseBody(); |
52 os.write(bb); |
52 os.write(bb); |
53 os.close(); |
53 os.close(); |
54 t.close(); |
54 t.close(); |
55 } |
55 } |
56 } |
56 } |
57 |
57 |
|
58 protected int redirectCode() { |
|
59 return 301; |
|
60 } |
|
61 |
58 // override in sub-class to examine the exchange, but don't |
62 // override in sub-class to examine the exchange, but don't |
59 // alter transaction state by reading the request body etc. |
63 // alter transaction state by reading the request body etc. |
60 protected void examineExchange(Http2TestExchange t) { |
64 protected void examineExchange(Http2TestExchange t) { |
61 } |
65 } |
62 } |
66 } |