1
1
/*
2
- * Copyright (c) 2018, 2023 , Oracle and/or its affiliates. All rights reserved.
2
+ * Copyright (c) 2018, 2025 , Oracle and/or its affiliates. All rights reserved.
3
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
4
*
5
5
* This code is free software; you can redistribute it and/or modify it
23
23
24
24
/*
25
25
* @test
26
- * @bug 8303965
26
+ * @bug 8303965 8354276
27
+ * @summary This test verifies the behaviour of the HttpClient when presented
28
+ * with a HEADERS frame followed by CONTINUATION frames, and when presented
29
+ * with bad header fields.
27
30
* @library /test/lib /test/jdk/java/net/httpclient/lib
28
31
* @build jdk.httpclient.test.lib.http2.Http2TestServer jdk.test.lib.net.SimpleSSLContext
29
32
* @run testng/othervm -Djdk.internal.httpclient.debug=true BadHeadersTest
44
47
import java .io .IOException ;
45
48
import java .io .InputStream ;
46
49
import java .io .OutputStream ;
50
+ import java .net .ProtocolException ;
47
51
import java .net .URI ;
48
52
import java .net .http .HttpClient ;
49
53
import java .net .http .HttpHeaders ;
@@ -76,6 +80,8 @@ public class BadHeadersTest {
76
80
of (entry (":status" , "200" ), entry ("hell o" , "value" )), // Space in the name
77
81
of (entry (":status" , "200" ), entry ("hello" , "line1\r \n line2\r \n " )), // Multiline value
78
82
of (entry (":status" , "200" ), entry ("hello" , "DE" + ((char ) 0x7F ) + "L" )), // Bad byte in value
83
+ of (entry (":status" , "200" ), entry ("connection" , "close" )), // Prohibited connection-specific header
84
+ of (entry (":status" , "200" ), entry (":scheme" , "https" )), // Request pseudo-header in response
79
85
of (entry ("hello" , "world!" ), entry (":status" , "200" )) // Pseudo header is not the first one
80
86
);
81
87
@@ -86,7 +92,7 @@ public class BadHeadersTest {
86
92
String https2URI ;
87
93
88
94
/**
89
- * A function that returns a list of 1) a HEADERS frame ( with an empty
95
+ * A function that returns a list of 1) one HEADERS frame ( with an empty
90
96
* payload ), and 2) a CONTINUATION frame with the actual headers.
91
97
*/
92
98
static BiFunction <Integer ,List <ByteBuffer >,List <Http2Frame >> oneContinuation =
@@ -100,7 +106,7 @@ public class BadHeadersTest {
100
106
};
101
107
102
108
/**
103
- * A function that returns a list of a HEADERS frame followed by a number of
109
+ * A function that returns a list of one HEADERS frame followed by a number of
104
110
* CONTINUATION frames. Each frame contains just a single byte of payload.
105
111
*/
106
112
static BiFunction <Integer ,List <ByteBuffer >,List <Http2Frame >> byteAtATime =
@@ -189,12 +195,13 @@ void testAsync(String uri,
189
195
try {
190
196
HttpResponse <String > response = cc .sendAsync (request , BodyHandlers .ofString ()).get ();
191
197
fail ("Expected exception, got :" + response + ", " + response .body ());
192
- } catch (Throwable t0 ) {
198
+ } catch (Exception t0 ) {
193
199
System .out .println ("Got EXPECTED: " + t0 );
194
200
if (t0 instanceof ExecutionException ) {
195
- t0 = t0 .getCause ();
201
+ t = t0 .getCause ();
202
+ } else {
203
+ t = t0 ;
196
204
}
197
- t = t0 ;
198
205
}
199
206
assertDetailMessage (t , i );
200
207
}
@@ -204,15 +211,21 @@ void testAsync(String uri,
204
211
// sync with implementation.
205
212
static void assertDetailMessage (Throwable throwable , int iterationIndex ) {
206
213
try {
207
- assertTrue (throwable instanceof IOException ,
208
- "Expected IOException , got, " + throwable );
214
+ assertTrue (throwable instanceof ProtocolException ,
215
+ "Expected ProtocolException , got " + throwable );
209
216
assertTrue (throwable .getMessage ().contains ("malformed response" ),
210
217
"Expected \" malformed response\" in: " + throwable .getMessage ());
211
218
212
219
if (iterationIndex == 0 ) { // unknown
213
220
assertTrue (throwable .getMessage ().contains ("Unknown pseudo-header" ),
214
221
"Expected \" Unknown pseudo-header\" in: " + throwable .getMessage ());
215
- } else if (iterationIndex == 4 ) { // unexpected
222
+ } else if (iterationIndex == 4 ) { // prohibited
223
+ assertTrue (throwable .getMessage ().contains ("Prohibited header name" ),
224
+ "Expected \" Prohibited header name\" in: " + throwable .getMessage ());
225
+ } else if (iterationIndex == 5 ) { // unexpected type
226
+ assertTrue (throwable .getMessage ().contains ("not valid in context" ),
227
+ "Expected \" not valid in context\" in: " + throwable .getMessage ());
228
+ } else if (iterationIndex == 6 ) { // unexpected sequence
216
229
assertTrue (throwable .getMessage ().contains (" Unexpected pseudo-header" ),
217
230
"Expected \" Unexpected pseudo-header\" in: " + throwable .getMessage ());
218
231
} else {
0 commit comments