author | chegar |
Tue, 17 Apr 2018 08:54:17 -0700 | |
changeset 49765 | ee6f7a61f3a5 |
parent 48703 | 3eae36c6baa5 |
child 50681 | 4254bed3c09d |
child 56451 | 9585061fdb04 |
permissions | -rw-r--r-- |
48703
3eae36c6baa5
8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff
changeset
|
1 |
/* |
3eae36c6baa5
8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff
changeset
|
2 |
* Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. |
3eae36c6baa5
8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
3eae36c6baa5
8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff
changeset
|
4 |
* |
3eae36c6baa5
8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
3eae36c6baa5
8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
3eae36c6baa5
8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
3eae36c6baa5
8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff
changeset
|
8 |
* |
3eae36c6baa5
8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
3eae36c6baa5
8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
3eae36c6baa5
8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
3eae36c6baa5
8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
3eae36c6baa5
8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff
changeset
|
13 |
* accompanied this code). |
3eae36c6baa5
8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff
changeset
|
14 |
* |
3eae36c6baa5
8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
3eae36c6baa5
8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
3eae36c6baa5
8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
3eae36c6baa5
8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff
changeset
|
18 |
* |
3eae36c6baa5
8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
3eae36c6baa5
8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
3eae36c6baa5
8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff
changeset
|
21 |
* questions. |
3eae36c6baa5
8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff
changeset
|
22 |
*/ |
3eae36c6baa5
8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff
changeset
|
23 |
|
3eae36c6baa5
8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff
changeset
|
24 |
/* |
3eae36c6baa5
8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff
changeset
|
25 |
* @test |
3eae36c6baa5
8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff
changeset
|
26 |
* @bug 8195823 |
3eae36c6baa5
8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff
changeset
|
27 |
* @summary Buffers given to response body subscribers should not contain |
3eae36c6baa5
8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff
changeset
|
28 |
* unprocessed HTTP data |
3eae36c6baa5
8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff
changeset
|
29 |
* @modules java.base/sun.net.www.http |
49765 | 30 |
* java.net.http/jdk.internal.net.http.common |
31 |
* java.net.http/jdk.internal.net.http.frame |
|
32 |
* java.net.http/jdk.internal.net.http.hpack |
|
48703
3eae36c6baa5
8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff
changeset
|
33 |
* java.logging |
3eae36c6baa5
8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff
changeset
|
34 |
* jdk.httpserver |
3eae36c6baa5
8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff
changeset
|
35 |
* @library /lib/testlibrary http2/server |
3eae36c6baa5
8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff
changeset
|
36 |
* @build Http2TestServer |
3eae36c6baa5
8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff
changeset
|
37 |
* @build jdk.testlibrary.SimpleSSLContext |
3eae36c6baa5
8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff
changeset
|
38 |
* @run testng/othervm -Djdk.internal.httpclient.debug=true ConcurrentResponses |
3eae36c6baa5
8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff
changeset
|
39 |
*/ |
3eae36c6baa5
8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff
changeset
|
40 |
|
3eae36c6baa5
8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff
changeset
|
41 |
import java.io.IOException; |
3eae36c6baa5
8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff
changeset
|
42 |
import java.io.InputStream; |
3eae36c6baa5
8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff
changeset
|
43 |
import java.io.OutputStream; |
49765 | 44 |
import java.net.InetAddress; |
48703
3eae36c6baa5
8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff
changeset
|
45 |
import java.net.InetSocketAddress; |
3eae36c6baa5
8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff
changeset
|
46 |
import java.net.URI; |
3eae36c6baa5
8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff
changeset
|
47 |
import java.nio.ByteBuffer; |
3eae36c6baa5
8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff
changeset
|
48 |
import java.util.HashMap; |
3eae36c6baa5
8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff
changeset
|
49 |
import java.util.List; |
3eae36c6baa5
8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff
changeset
|
50 |
import java.util.Map; |
3eae36c6baa5
8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff
changeset
|
51 |
import java.util.concurrent.CompletableFuture; |
3eae36c6baa5
8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff
changeset
|
52 |
import java.util.concurrent.CompletionStage; |
3eae36c6baa5
8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff
changeset
|
53 |
import java.util.concurrent.Flow; |
3eae36c6baa5
8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff
changeset
|
54 |
import java.util.stream.IntStream; |
3eae36c6baa5
8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff
changeset
|
55 |
import javax.net.ssl.SSLContext; |
3eae36c6baa5
8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff
changeset
|
56 |
import com.sun.net.httpserver.HttpExchange; |
3eae36c6baa5
8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff
changeset
|
57 |
import com.sun.net.httpserver.HttpHandler; |
3eae36c6baa5
8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff
changeset
|
58 |
import com.sun.net.httpserver.HttpServer; |
3eae36c6baa5
8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff
changeset
|
59 |
import com.sun.net.httpserver.HttpsConfigurator; |
3eae36c6baa5
8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff
changeset
|
60 |
import com.sun.net.httpserver.HttpsServer; |
49765 | 61 |
import java.net.http.HttpClient; |
62 |
import java.net.http.HttpRequest; |
|
63 |
import java.net.http.HttpResponse; |
|
64 |
import java.net.http.HttpResponse.BodyHandler; |
|
65 |
import java.net.http.HttpResponse.BodyHandlers; |
|
66 |
import java.net.http.HttpResponse.BodySubscriber; |
|
67 |
import java.net.http.HttpResponse.BodySubscribers; |
|
48703
3eae36c6baa5
8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff
changeset
|
68 |
import jdk.testlibrary.SimpleSSLContext; |
3eae36c6baa5
8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff
changeset
|
69 |
import org.testng.annotations.AfterTest; |
3eae36c6baa5
8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff
changeset
|
70 |
import org.testng.annotations.BeforeTest; |
3eae36c6baa5
8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff
changeset
|
71 |
import org.testng.annotations.DataProvider; |
3eae36c6baa5
8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff
changeset
|
72 |
import org.testng.annotations.Test; |
3eae36c6baa5
8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff
changeset
|
73 |
import static java.nio.charset.StandardCharsets.UTF_8; |
49765 | 74 |
import static java.net.http.HttpResponse.BodyHandlers.discarding; |
48703
3eae36c6baa5
8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff
changeset
|
75 |
import static org.testng.Assert.assertEquals; |
3eae36c6baa5
8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff
changeset
|
76 |
import static org.testng.Assert.assertFalse; |
3eae36c6baa5
8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff
changeset
|
77 |
import static org.testng.Assert.fail; |
3eae36c6baa5
8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff
changeset
|
78 |
|
3eae36c6baa5
8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff
changeset
|
79 |
public class ConcurrentResponses { |
3eae36c6baa5
8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff
changeset
|
80 |
|
3eae36c6baa5
8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff
changeset
|
81 |
SSLContext sslContext; |
3eae36c6baa5
8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff
changeset
|
82 |
HttpServer httpTestServer; // HTTP/1.1 [ 4 servers ] |
3eae36c6baa5
8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff
changeset
|
83 |
HttpsServer httpsTestServer; // HTTPS/1.1 |
3eae36c6baa5
8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff
changeset
|
84 |
Http2TestServer http2TestServer; // HTTP/2 ( h2c ) |
3eae36c6baa5
8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff
changeset
|
85 |
Http2TestServer https2TestServer; // HTTP/2 ( h2 ) |
3eae36c6baa5
8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff
changeset
|
86 |
String httpFixedURI, httpsFixedURI, httpChunkedURI, httpsChunkedURI; |
3eae36c6baa5
8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff
changeset
|
87 |
String http2FixedURI, https2FixedURI, http2VariableURI, https2VariableURI; |
3eae36c6baa5
8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff
changeset
|
88 |
|
3eae36c6baa5
8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff
changeset
|
89 |
static final int CONCURRENT_REQUESTS = 13; |
3eae36c6baa5
8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff
changeset
|
90 |
|
3eae36c6baa5
8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff
changeset
|
91 |
static final String ALPHABET = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; |
3eae36c6baa5
8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff
changeset
|
92 |
static final int ALPHABET_LENGTH = ALPHABET.length(); |
3eae36c6baa5
8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff
changeset
|
93 |
|
3eae36c6baa5
8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff
changeset
|
94 |
static final String stringOfLength(int requiredLength) { |
3eae36c6baa5
8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff
changeset
|
95 |
StringBuilder sb = new StringBuilder(requiredLength); |
3eae36c6baa5
8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff
changeset
|
96 |
IntStream.range(0, requiredLength) |
3eae36c6baa5
8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff
changeset
|
97 |
.mapToObj(i -> ALPHABET.charAt(i % ALPHABET_LENGTH)) |
3eae36c6baa5
8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff
changeset
|
98 |
.forEach(c -> sb.append(c)); |
3eae36c6baa5
8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff
changeset
|
99 |
return sb.toString(); |
3eae36c6baa5
8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff
changeset
|
100 |
} |
3eae36c6baa5
8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff
changeset
|
101 |
|
3eae36c6baa5
8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff
changeset
|
102 |
/** An array of different Strings, to be used as bodies. */ |
3eae36c6baa5
8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff
changeset
|
103 |
static final String[] BODIES = bodies(); |
3eae36c6baa5
8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff
changeset
|
104 |
|
3eae36c6baa5
8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff
changeset
|
105 |
static String[] bodies() { |
3eae36c6baa5
8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff
changeset
|
106 |
String[] bodies = new String[CONCURRENT_REQUESTS]; |
3eae36c6baa5
8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff
changeset
|
107 |
for (int i=0;i<CONCURRENT_REQUESTS; i++) { |
3eae36c6baa5
8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff
changeset
|
108 |
// slightly, but still, different bodies |
3eae36c6baa5
8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff
changeset
|
109 |
bodies[i] = "Request-" + i + "-body-" + stringOfLength((1024) + i); |
3eae36c6baa5
8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff
changeset
|
110 |
} |
3eae36c6baa5
8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff
changeset
|
111 |
return bodies; |
3eae36c6baa5
8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff
changeset
|
112 |
} |
3eae36c6baa5
8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff
changeset
|
113 |
|
3eae36c6baa5
8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff
changeset
|
114 |
/** |
3eae36c6baa5
8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff
changeset
|
115 |
* Asserts the given response's status code is 200. |
3eae36c6baa5
8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff
changeset
|
116 |
* Returns a CF that completes with the given response. |
3eae36c6baa5
8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff
changeset
|
117 |
*/ |
3eae36c6baa5
8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff
changeset
|
118 |
static final <T> CompletionStage<HttpResponse<T>> |
3eae36c6baa5
8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff
changeset
|
119 |
assert200ResponseCode(HttpResponse<T> response) { |
3eae36c6baa5
8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff
changeset
|
120 |
assertEquals(response.statusCode(), 200); |
3eae36c6baa5
8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff
changeset
|
121 |
return CompletableFuture.completedFuture(response); |
3eae36c6baa5
8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff
changeset
|
122 |
} |
3eae36c6baa5
8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff
changeset
|
123 |
|
3eae36c6baa5
8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff
changeset
|
124 |
/** |
3eae36c6baa5
8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff
changeset
|
125 |
* Asserts that the given response's body is equal to the given body. |
3eae36c6baa5
8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff
changeset
|
126 |
* Returns a CF that completes with the given response. |
3eae36c6baa5
8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff
changeset
|
127 |
*/ |
3eae36c6baa5
8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff
changeset
|
128 |
static final <T> CompletionStage<HttpResponse<T>> |
3eae36c6baa5
8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff
changeset
|
129 |
assertbody(HttpResponse<T> response, T body) { |
3eae36c6baa5
8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff
changeset
|
130 |
assertEquals(response.body(), body); |
3eae36c6baa5
8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff
changeset
|
131 |
return CompletableFuture.completedFuture(response); |
3eae36c6baa5
8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff
changeset
|
132 |
} |
3eae36c6baa5
8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff
changeset
|
133 |
|
3eae36c6baa5
8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff
changeset
|
134 |
@DataProvider(name = "uris") |
3eae36c6baa5
8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff
changeset
|
135 |
public Object[][] variants() { |
3eae36c6baa5
8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff
changeset
|
136 |
return new Object[][]{ |
3eae36c6baa5
8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff
changeset
|
137 |
{ httpFixedURI }, |
3eae36c6baa5
8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff
changeset
|
138 |
{ httpsFixedURI }, |
3eae36c6baa5
8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff
changeset
|
139 |
{ httpChunkedURI }, |
3eae36c6baa5
8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff
changeset
|
140 |
{ httpsChunkedURI }, |
3eae36c6baa5
8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff
changeset
|
141 |
{ http2FixedURI }, |
3eae36c6baa5
8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff
changeset
|
142 |
{ https2FixedURI }, |
3eae36c6baa5
8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff
changeset
|
143 |
{ http2VariableURI }, |
3eae36c6baa5
8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff
changeset
|
144 |
{ https2VariableURI } |
3eae36c6baa5
8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff
changeset
|
145 |
}; |
3eae36c6baa5
8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff
changeset
|
146 |
} |
3eae36c6baa5
8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff
changeset
|
147 |
|
3eae36c6baa5
8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff
changeset
|
148 |
|
49765 | 149 |
// The ofString implementation accumulates data, below a certain threshold |
48703
3eae36c6baa5
8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff
changeset
|
150 |
// into the byte buffers it is given. |
3eae36c6baa5
8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff
changeset
|
151 |
@Test(dataProvider = "uris") |
3eae36c6baa5
8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff
changeset
|
152 |
void testAsString(String uri) throws Exception { |
3eae36c6baa5
8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff
changeset
|
153 |
HttpClient client = HttpClient.newBuilder().sslContext(sslContext).build(); |
3eae36c6baa5
8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff
changeset
|
154 |
|
3eae36c6baa5
8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff
changeset
|
155 |
Map<HttpRequest, String> requests = new HashMap<>(); |
3eae36c6baa5
8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff
changeset
|
156 |
for (int i=0;i<CONCURRENT_REQUESTS; i++) { |
3eae36c6baa5
8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff
changeset
|
157 |
HttpRequest request = HttpRequest.newBuilder(URI.create(uri + "?" + i)) |
3eae36c6baa5
8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff
changeset
|
158 |
.build(); |
3eae36c6baa5
8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff
changeset
|
159 |
requests.put(request, BODIES[i]); |
3eae36c6baa5
8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff
changeset
|
160 |
} |
3eae36c6baa5
8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff
changeset
|
161 |
|
3eae36c6baa5
8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff
changeset
|
162 |
// initial connection to seed the cache so next parallel connections reuse it |
49765 | 163 |
client.sendAsync(HttpRequest.newBuilder(URI.create(uri)).build(), discarding()).join(); |
48703
3eae36c6baa5
8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff
changeset
|
164 |
|
3eae36c6baa5
8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff
changeset
|
165 |
// will reuse connection cached from the previous request ( when HTTP/2 ) |
3eae36c6baa5
8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff
changeset
|
166 |
CompletableFuture.allOf(requests.keySet().parallelStream() |
49765 | 167 |
.map(request -> client.sendAsync(request, BodyHandlers.ofString())) |
48703
3eae36c6baa5
8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff
changeset
|
168 |
.map(cf -> cf.thenCompose(ConcurrentResponses::assert200ResponseCode)) |
3eae36c6baa5
8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff
changeset
|
169 |
.map(cf -> cf.thenCompose(response -> assertbody(response, requests.get(response.request())))) |
3eae36c6baa5
8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff
changeset
|
170 |
.toArray(CompletableFuture<?>[]::new)) |
3eae36c6baa5
8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff
changeset
|
171 |
.join(); |
3eae36c6baa5
8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff
changeset
|
172 |
} |
3eae36c6baa5
8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff
changeset
|
173 |
|
3eae36c6baa5
8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff
changeset
|
174 |
// The custom subscriber aggressively attacks any area, between the limit |
3eae36c6baa5
8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff
changeset
|
175 |
// and the capacity, in the byte buffers it is given, by writing 'X' into it. |
3eae36c6baa5
8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff
changeset
|
176 |
@Test(dataProvider = "uris") |
3eae36c6baa5
8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff
changeset
|
177 |
void testWithCustomSubscriber(String uri) throws Exception { |
3eae36c6baa5
8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff
changeset
|
178 |
HttpClient client = HttpClient.newBuilder().sslContext(sslContext).build(); |
3eae36c6baa5
8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff
changeset
|
179 |
|
3eae36c6baa5
8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff
changeset
|
180 |
Map<HttpRequest, String> requests = new HashMap<>(); |
3eae36c6baa5
8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff
changeset
|
181 |
for (int i=0;i<CONCURRENT_REQUESTS; i++) { |
3eae36c6baa5
8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff
changeset
|
182 |
HttpRequest request = HttpRequest.newBuilder(URI.create(uri + "?" + i)) |
3eae36c6baa5
8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff
changeset
|
183 |
.build(); |
3eae36c6baa5
8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff
changeset
|
184 |
requests.put(request, BODIES[i]); |
3eae36c6baa5
8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff
changeset
|
185 |
} |
3eae36c6baa5
8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff
changeset
|
186 |
|
3eae36c6baa5
8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff
changeset
|
187 |
// initial connection to seed the cache so next parallel connections reuse it |
49765 | 188 |
client.sendAsync(HttpRequest.newBuilder(URI.create(uri)).build(), discarding()).join(); |
48703
3eae36c6baa5
8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff
changeset
|
189 |
|
3eae36c6baa5
8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff
changeset
|
190 |
// will reuse connection cached from the previous request ( when HTTP/2 ) |
3eae36c6baa5
8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff
changeset
|
191 |
CompletableFuture.allOf(requests.keySet().parallelStream() |
3eae36c6baa5
8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff
changeset
|
192 |
.map(request -> client.sendAsync(request, CustomSubscriber.handler)) |
3eae36c6baa5
8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff
changeset
|
193 |
.map(cf -> cf.thenCompose(ConcurrentResponses::assert200ResponseCode)) |
3eae36c6baa5
8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff
changeset
|
194 |
.map(cf -> cf.thenCompose(response -> assertbody(response, requests.get(response.request())))) |
3eae36c6baa5
8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff
changeset
|
195 |
.toArray(CompletableFuture<?>[]::new)) |
3eae36c6baa5
8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff
changeset
|
196 |
.join(); |
3eae36c6baa5
8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff
changeset
|
197 |
} |
3eae36c6baa5
8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff
changeset
|
198 |
|
3eae36c6baa5
8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff
changeset
|
199 |
/** |
49765 | 200 |
* A subscriber that wraps ofString, but mucks with any data between limit |
48703
3eae36c6baa5
8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff
changeset
|
201 |
* and capacity, if the client mistakenly passes it any that is should not. |
3eae36c6baa5
8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff
changeset
|
202 |
*/ |
3eae36c6baa5
8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff
changeset
|
203 |
static class CustomSubscriber implements BodySubscriber<String> { |
49765 | 204 |
static final BodyHandler<String> handler = (r) -> new CustomSubscriber(); |
205 |
private final BodySubscriber<String> ofString = BodySubscribers.ofString(UTF_8); |
|
48703
3eae36c6baa5
8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff
changeset
|
206 |
|
3eae36c6baa5
8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff
changeset
|
207 |
@Override |
3eae36c6baa5
8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff
changeset
|
208 |
public CompletionStage<String> getBody() { |
49765 | 209 |
return ofString.getBody(); |
48703
3eae36c6baa5
8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff
changeset
|
210 |
} |
3eae36c6baa5
8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff
changeset
|
211 |
|
3eae36c6baa5
8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff
changeset
|
212 |
@Override |
3eae36c6baa5
8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff
changeset
|
213 |
public void onSubscribe(Flow.Subscription subscription) { |
49765 | 214 |
ofString.onSubscribe(subscription); |
48703
3eae36c6baa5
8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff
changeset
|
215 |
} |
3eae36c6baa5
8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff
changeset
|
216 |
|
3eae36c6baa5
8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff
changeset
|
217 |
@Override |
3eae36c6baa5
8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff
changeset
|
218 |
public void onNext(List<ByteBuffer> buffers) { |
3eae36c6baa5
8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff
changeset
|
219 |
// Muck any data beyond the give limit, since there shouldn't |
3eae36c6baa5
8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff
changeset
|
220 |
// be any of interest to the HTTP Client. |
3eae36c6baa5
8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff
changeset
|
221 |
for (ByteBuffer buffer : buffers) { |
49765 | 222 |
if (buffer.isReadOnly()) |
223 |
continue; |
|
224 |
||
48703
3eae36c6baa5
8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff
changeset
|
225 |
if (buffer.limit() != buffer.capacity()) { |
3eae36c6baa5
8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff
changeset
|
226 |
final int limit = buffer.limit(); |
3eae36c6baa5
8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff
changeset
|
227 |
final int position = buffer.position(); |
3eae36c6baa5
8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff
changeset
|
228 |
buffer.position(buffer.limit()); |
3eae36c6baa5
8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff
changeset
|
229 |
buffer.limit(buffer.capacity()); |
3eae36c6baa5
8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff
changeset
|
230 |
while (buffer.hasRemaining()) |
3eae36c6baa5
8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff
changeset
|
231 |
buffer.put((byte)'X'); |
3eae36c6baa5
8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff
changeset
|
232 |
buffer.position(position); // restore original position |
3eae36c6baa5
8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff
changeset
|
233 |
buffer.limit(limit); // restore original limit |
3eae36c6baa5
8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff
changeset
|
234 |
} |
3eae36c6baa5
8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff
changeset
|
235 |
} |
49765 | 236 |
ofString.onNext(buffers); |
48703
3eae36c6baa5
8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff
changeset
|
237 |
} |
3eae36c6baa5
8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff
changeset
|
238 |
|
3eae36c6baa5
8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff
changeset
|
239 |
@Override |
3eae36c6baa5
8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff
changeset
|
240 |
public void onError(Throwable throwable) { |
49765 | 241 |
ofString.onError(throwable); |
48703
3eae36c6baa5
8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff
changeset
|
242 |
throwable.printStackTrace(); |
3eae36c6baa5
8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff
changeset
|
243 |
fail("UNEXPECTED:" + throwable); |
3eae36c6baa5
8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff
changeset
|
244 |
} |
3eae36c6baa5
8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff
changeset
|
245 |
|
3eae36c6baa5
8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff
changeset
|
246 |
@Override |
3eae36c6baa5
8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff
changeset
|
247 |
public void onComplete() { |
49765 | 248 |
ofString.onComplete(); |
48703
3eae36c6baa5
8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff
changeset
|
249 |
} |
3eae36c6baa5
8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff
changeset
|
250 |
} |
3eae36c6baa5
8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff
changeset
|
251 |
|
49765 | 252 |
static String serverAuthority(HttpServer server) { |
253 |
return InetAddress.getLoopbackAddress().getHostName() + ":" |
|
254 |
+ server.getAddress().getPort(); |
|
255 |
} |
|
48703
3eae36c6baa5
8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff
changeset
|
256 |
|
3eae36c6baa5
8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff
changeset
|
257 |
@BeforeTest |
3eae36c6baa5
8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff
changeset
|
258 |
public void setup() throws Exception { |
3eae36c6baa5
8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff
changeset
|
259 |
sslContext = new SimpleSSLContext().get(); |
3eae36c6baa5
8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff
changeset
|
260 |
if (sslContext == null) |
3eae36c6baa5
8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff
changeset
|
261 |
throw new AssertionError("Unexpected null sslContext"); |
3eae36c6baa5
8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff
changeset
|
262 |
|
49765 | 263 |
InetSocketAddress sa = new InetSocketAddress(InetAddress.getLoopbackAddress(), 0); |
48703
3eae36c6baa5
8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff
changeset
|
264 |
httpTestServer = HttpServer.create(sa, 0); |
3eae36c6baa5
8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff
changeset
|
265 |
httpTestServer.createContext("/http1/fixed", new Http1FixedHandler()); |
49765 | 266 |
httpFixedURI = "http://" + serverAuthority(httpTestServer) + "/http1/fixed"; |
48703
3eae36c6baa5
8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff
changeset
|
267 |
httpTestServer.createContext("/http1/chunked", new Http1ChunkedHandler()); |
49765 | 268 |
httpChunkedURI = "http://" + serverAuthority(httpTestServer) + "/http1/chunked"; |
48703
3eae36c6baa5
8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff
changeset
|
269 |
|
3eae36c6baa5
8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff
changeset
|
270 |
httpsTestServer = HttpsServer.create(sa, 0); |
3eae36c6baa5
8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff
changeset
|
271 |
httpsTestServer.setHttpsConfigurator(new HttpsConfigurator(sslContext)); |
3eae36c6baa5
8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff
changeset
|
272 |
httpsTestServer.createContext("/https1/fixed", new Http1FixedHandler()); |
49765 | 273 |
httpsFixedURI = "https://" + serverAuthority(httpsTestServer) + "/https1/fixed"; |
48703
3eae36c6baa5
8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff
changeset
|
274 |
httpsTestServer.createContext("/https1/chunked", new Http1ChunkedHandler()); |
49765 | 275 |
httpsChunkedURI = "https://" + serverAuthority(httpsTestServer) + "/https1/chunked"; |
48703
3eae36c6baa5
8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff
changeset
|
276 |
|
49765 | 277 |
http2TestServer = new Http2TestServer("localhost", false, 0); |
48703
3eae36c6baa5
8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff
changeset
|
278 |
http2TestServer.addHandler(new Http2FixedHandler(), "/http2/fixed"); |
49765 | 279 |
http2FixedURI = "http://" + http2TestServer.serverAuthority()+ "/http2/fixed"; |
48703
3eae36c6baa5
8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff
changeset
|
280 |
http2TestServer.addHandler(new Http2VariableHandler(), "/http2/variable"); |
49765 | 281 |
http2VariableURI = "http://" + http2TestServer.serverAuthority() + "/http2/variable"; |
48703
3eae36c6baa5
8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff
changeset
|
282 |
|
49765 | 283 |
https2TestServer = new Http2TestServer("localhost", true, 0); |
48703
3eae36c6baa5
8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff
changeset
|
284 |
https2TestServer.addHandler(new Http2FixedHandler(), "/https2/fixed"); |
49765 | 285 |
https2FixedURI = "https://" + https2TestServer.serverAuthority() + "/https2/fixed"; |
48703
3eae36c6baa5
8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff
changeset
|
286 |
https2TestServer.addHandler(new Http2VariableHandler(), "/https2/variable"); |
49765 | 287 |
https2VariableURI = "https://" + https2TestServer.serverAuthority() + "/https2/variable"; |
48703
3eae36c6baa5
8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff
changeset
|
288 |
|
3eae36c6baa5
8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff
changeset
|
289 |
httpTestServer.start(); |
3eae36c6baa5
8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff
changeset
|
290 |
httpsTestServer.start(); |
3eae36c6baa5
8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff
changeset
|
291 |
http2TestServer.start(); |
3eae36c6baa5
8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff
changeset
|
292 |
https2TestServer.start(); |
3eae36c6baa5
8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff
changeset
|
293 |
} |
3eae36c6baa5
8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff
changeset
|
294 |
|
3eae36c6baa5
8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff
changeset
|
295 |
@AfterTest |
3eae36c6baa5
8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff
changeset
|
296 |
public void teardown() throws Exception { |
3eae36c6baa5
8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff
changeset
|
297 |
httpTestServer.stop(0); |
3eae36c6baa5
8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff
changeset
|
298 |
httpsTestServer.stop(0); |
3eae36c6baa5
8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff
changeset
|
299 |
http2TestServer.stop(); |
3eae36c6baa5
8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff
changeset
|
300 |
https2TestServer.stop(); |
3eae36c6baa5
8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff
changeset
|
301 |
} |
3eae36c6baa5
8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff
changeset
|
302 |
|
3eae36c6baa5
8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff
changeset
|
303 |
interface SendResponseHeadersFunction { |
3eae36c6baa5
8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff
changeset
|
304 |
void apply(int responseCode, long responseLength) throws IOException; |
3eae36c6baa5
8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff
changeset
|
305 |
} |
3eae36c6baa5
8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff
changeset
|
306 |
|
3eae36c6baa5
8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff
changeset
|
307 |
// A handler implementation that replies with 200 OK. If the exchange's uri |
3eae36c6baa5
8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff
changeset
|
308 |
// has a query, then it must be an integer, which is used as an index to |
3eae36c6baa5
8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff
changeset
|
309 |
// select the particular response body, e.g. /http2/x?5 -> BODIES[5] |
3eae36c6baa5
8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff
changeset
|
310 |
static void serverHandlerImpl(InputStream inputStream, |
3eae36c6baa5
8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff
changeset
|
311 |
OutputStream outputStream, |
3eae36c6baa5
8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff
changeset
|
312 |
URI uri, |
3eae36c6baa5
8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff
changeset
|
313 |
SendResponseHeadersFunction sendResponseHeadersFunction) |
3eae36c6baa5
8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff
changeset
|
314 |
throws IOException |
3eae36c6baa5
8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff
changeset
|
315 |
{ |
3eae36c6baa5
8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff
changeset
|
316 |
try (InputStream is = inputStream; |
3eae36c6baa5
8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff
changeset
|
317 |
OutputStream os = outputStream) { |
3eae36c6baa5
8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff
changeset
|
318 |
is.readAllBytes(); |
3eae36c6baa5
8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff
changeset
|
319 |
|
3eae36c6baa5
8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff
changeset
|
320 |
String magicQuery = uri.getQuery(); |
3eae36c6baa5
8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff
changeset
|
321 |
if (magicQuery != null) { |
3eae36c6baa5
8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff
changeset
|
322 |
int bodyIndex = Integer.valueOf(magicQuery); |
3eae36c6baa5
8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff
changeset
|
323 |
String body = BODIES[bodyIndex]; |
3eae36c6baa5
8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff
changeset
|
324 |
byte[] bytes = body.getBytes(UTF_8); |
3eae36c6baa5
8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff
changeset
|
325 |
sendResponseHeadersFunction.apply(200, bytes.length); |
3eae36c6baa5
8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff
changeset
|
326 |
int offset = 0; |
3eae36c6baa5
8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff
changeset
|
327 |
// Deliberately attempt to reply with several relatively |
3eae36c6baa5
8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff
changeset
|
328 |
// small data frames ( each write corresponds to its own |
3eae36c6baa5
8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff
changeset
|
329 |
// data frame ). Additionally, yield, to encourage other |
3eae36c6baa5
8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff
changeset
|
330 |
// handlers to execute, therefore increasing the likelihood |
3eae36c6baa5
8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff
changeset
|
331 |
// of multiple different-stream related frames in the |
3eae36c6baa5
8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff
changeset
|
332 |
// client's read buffer. |
3eae36c6baa5
8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff
changeset
|
333 |
while (offset < bytes.length) { |
3eae36c6baa5
8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff
changeset
|
334 |
int length = Math.min(bytes.length - offset, 64); |
3eae36c6baa5
8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff
changeset
|
335 |
os.write(bytes, offset, length); |
3eae36c6baa5
8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff
changeset
|
336 |
os.flush(); |
3eae36c6baa5
8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff
changeset
|
337 |
offset += length; |
3eae36c6baa5
8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff
changeset
|
338 |
Thread.yield(); |
3eae36c6baa5
8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff
changeset
|
339 |
} |
3eae36c6baa5
8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff
changeset
|
340 |
} else { |
3eae36c6baa5
8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff
changeset
|
341 |
sendResponseHeadersFunction.apply(200, 1); |
3eae36c6baa5
8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff
changeset
|
342 |
os.write('A'); |
3eae36c6baa5
8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff
changeset
|
343 |
} |
3eae36c6baa5
8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff
changeset
|
344 |
} |
3eae36c6baa5
8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff
changeset
|
345 |
} |
3eae36c6baa5
8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff
changeset
|
346 |
|
3eae36c6baa5
8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff
changeset
|
347 |
static class Http1FixedHandler implements HttpHandler { |
3eae36c6baa5
8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff
changeset
|
348 |
@Override |
3eae36c6baa5
8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff
changeset
|
349 |
public void handle(HttpExchange t) throws IOException { |
3eae36c6baa5
8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff
changeset
|
350 |
serverHandlerImpl(t.getRequestBody(), |
3eae36c6baa5
8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff
changeset
|
351 |
t.getResponseBody(), |
3eae36c6baa5
8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff
changeset
|
352 |
t.getRequestURI(), |
3eae36c6baa5
8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff
changeset
|
353 |
(rcode, length) -> t.sendResponseHeaders(rcode, length)); |
3eae36c6baa5
8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff
changeset
|
354 |
} |
3eae36c6baa5
8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff
changeset
|
355 |
} |
3eae36c6baa5
8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff
changeset
|
356 |
|
3eae36c6baa5
8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff
changeset
|
357 |
static class Http1ChunkedHandler implements HttpHandler { |
3eae36c6baa5
8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff
changeset
|
358 |
@Override |
3eae36c6baa5
8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff
changeset
|
359 |
public void handle(HttpExchange t) throws IOException { |
3eae36c6baa5
8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff
changeset
|
360 |
serverHandlerImpl(t.getRequestBody(), |
3eae36c6baa5
8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff
changeset
|
361 |
t.getResponseBody(), |
3eae36c6baa5
8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff
changeset
|
362 |
t.getRequestURI(), |
3eae36c6baa5
8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff
changeset
|
363 |
(rcode, ignored) -> t.sendResponseHeaders(rcode, 0 /*chunked*/)); |
3eae36c6baa5
8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff
changeset
|
364 |
} |
3eae36c6baa5
8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff
changeset
|
365 |
} |
3eae36c6baa5
8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff
changeset
|
366 |
|
3eae36c6baa5
8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff
changeset
|
367 |
static class Http2FixedHandler implements Http2Handler { |
3eae36c6baa5
8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff
changeset
|
368 |
@Override |
3eae36c6baa5
8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff
changeset
|
369 |
public void handle(Http2TestExchange t) throws IOException { |
3eae36c6baa5
8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff
changeset
|
370 |
serverHandlerImpl(t.getRequestBody(), |
3eae36c6baa5
8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff
changeset
|
371 |
t.getResponseBody(), |
3eae36c6baa5
8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff
changeset
|
372 |
t.getRequestURI(), |
3eae36c6baa5
8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff
changeset
|
373 |
(rcode, length) -> t.sendResponseHeaders(rcode, length)); |
3eae36c6baa5
8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff
changeset
|
374 |
} |
3eae36c6baa5
8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff
changeset
|
375 |
} |
3eae36c6baa5
8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff
changeset
|
376 |
|
3eae36c6baa5
8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff
changeset
|
377 |
static class Http2VariableHandler implements Http2Handler { |
3eae36c6baa5
8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff
changeset
|
378 |
@Override |
3eae36c6baa5
8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff
changeset
|
379 |
public void handle(Http2TestExchange t) throws IOException { |
3eae36c6baa5
8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff
changeset
|
380 |
serverHandlerImpl(t.getRequestBody(), |
3eae36c6baa5
8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff
changeset
|
381 |
t.getResponseBody(), |
3eae36c6baa5
8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff
changeset
|
382 |
t.getRequestURI(), |
3eae36c6baa5
8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff
changeset
|
383 |
(rcode, ignored) -> t.sendResponseHeaders(rcode, 0 /* no Content-Length */)); |
3eae36c6baa5
8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff
changeset
|
384 |
} |
3eae36c6baa5
8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff
changeset
|
385 |
} |
3eae36c6baa5
8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff
changeset
|
386 |
} |