Skip to content

Commit a0fd011

Browse files
committed
Refactor to remove unnecessary parameter
1 parent 16b1bd4 commit a0fd011

31 files changed

+216
-191
lines changed

java/org/apache/coyote/http2/Http2Parser.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,12 +64,30 @@ class Http2Parser {
6464
* <code>false</code>
6565
*
6666
* @throws IOException If an IO error occurs while trying to read a frame
67+
*
68+
* @deprecated Unused. Will be removed in Tomcat 11 onwards.
6769
*/
70+
@Deprecated
6871
boolean readFrame(boolean block) throws Http2Exception, IOException {
6972
return readFrame(block, null);
7073
}
7174

7275

76+
/**
77+
* Read and process a single frame. The initial read is non-blocking to
78+
* determine if a frame is present. Once the start of a frame is read, the
79+
* remainder will be read using blocking IO.
80+
*
81+
* @return <code>true</code> if a frame was read otherwise
82+
* <code>false</code>
83+
*
84+
* @throws IOException If an IO error occurs while trying to read a frame
85+
*/
86+
boolean readFrame() throws Http2Exception, IOException {
87+
return readFrame(false, null);
88+
}
89+
90+
7391
private boolean readFrame(boolean block, FrameType expected)
7492
throws IOException, Http2Exception {
7593

java/org/apache/coyote/http2/Http2UpgradeHandler.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,7 @@ public SocketState upgradeDispatch(SocketEvent status) {
344344
setConnectionTimeout(-1);
345345
while (true) {
346346
try {
347-
if (!parser.readFrame(false)) {
347+
if (!parser.readFrame()) {
348348
break;
349349
}
350350
} catch (StreamException se) {

test/org/apache/coyote/http2/Http2TestBase.java

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -134,11 +134,11 @@ protected void validateHttp2InitialResponse() throws Exception {
134134
// - ping
135135
// - headers (for response)
136136
// - data (for response body)
137-
parser.readFrame(true);
138-
parser.readFrame(true);
139-
parser.readFrame(true);
140-
parser.readFrame(true);
141-
parser.readFrame(true);
137+
parser.readFrame();
138+
parser.readFrame();
139+
parser.readFrame();
140+
parser.readFrame();
141+
parser.readFrame();
142142

143143
Assert.assertEquals("0-Settings-[3]-[200]\n" +
144144
"0-Settings-End\n" +
@@ -461,9 +461,9 @@ protected void writeFrame(byte[] header, ByteBuffer payload, int offset, int len
461461

462462
protected void readSimpleGetResponse() throws Http2Exception, IOException {
463463
// Headers
464-
parser.readFrame(true);
464+
parser.readFrame();
465465
// Body
466-
parser.readFrame(true);
466+
parser.readFrame();
467467
}
468468

469469

@@ -478,23 +478,23 @@ protected void readSimplePostResponse(boolean padding) throws Http2Exception, IO
478478
*/
479479

480480
// Connection window update after reading request body
481-
parser.readFrame(true);
481+
parser.readFrame();
482482
// Stream window update after reading request body
483-
parser.readFrame(true);
483+
parser.readFrame();
484484
// Headers
485-
parser.readFrame(true);
485+
parser.readFrame();
486486
// Body (includes end of stream)
487-
parser.readFrame(true);
487+
parser.readFrame();
488488

489489
if (padding) {
490490
// Connection window update for padding
491-
parser.readFrame(true);
491+
parser.readFrame();
492492

493493
// If EndOfStream has not been received then the stream window
494494
// update must have been received so a further frame needs to be
495495
// read for EndOfStream.
496496
if (!output.getTrace().contains("EndOfStream")) {
497-
parser.readFrame(true);
497+
parser.readFrame();
498498
}
499499
}
500500
}
@@ -927,15 +927,15 @@ void handleGoAwayResponse(int lastStream) throws Http2Exception, IOException {
927927
protected void skipWindowSizeFrames() throws Http2Exception, IOException {
928928
do {
929929
output.clearTrace();
930-
parser.readFrame(true);
930+
parser.readFrame();
931931
} while (output.getTrace().contains("WindowSize"));
932932
}
933933

934934

935935
void handleGoAwayResponse(int lastStream, Http2Error expectedError)
936936
throws Http2Exception, IOException {
937937
try {
938-
parser.readFrame(true);
938+
parser.readFrame();
939939

940940
Assert.assertTrue(output.getTrace(), output.getTrace().startsWith(
941941
"0-Goaway-[" + lastStream + "]-[" + expectedError.getCode() + "]-["));

test/org/apache/coyote/http2/TestAsync.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -149,12 +149,12 @@ public void testEmptyWindow() throws Exception {
149149
}
150150

151151
// Headers
152-
parser.readFrame(true);
152+
parser.readFrame();
153153
// Body
154154

155155
if (!connectionUnlimited || !streamUnlimited) {
156156
while (output.getBytesRead() < startingWindowSize) {
157-
parser.readFrame(true);
157+
parser.readFrame();
158158
}
159159

160160
// Check that the right number of bytes were received
@@ -171,7 +171,7 @@ public void testEmptyWindow() throws Exception {
171171
}
172172

173173
while (output.getBytesRead() < startingWindowSize + windowSizeIncrease) {
174-
parser.readFrame(true);
174+
parser.readFrame();
175175
}
176176

177177
// Check that the right number of bytes were received
@@ -188,7 +188,7 @@ public void testEmptyWindow() throws Exception {
188188
}
189189

190190
while (!output.getTrace().endsWith("3-EndOfStream\n")) {
191-
parser.readFrame(true);
191+
parser.readFrame();
192192
}
193193

194194
// Check that the right number of bytes were received

test/org/apache/coyote/http2/TestAsyncFlush.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ public void testFlush() throws Exception {
8585
writeFrame(frameHeader, headersPayload);
8686

8787
// Headers
88-
parser.readFrame(true);
88+
parser.readFrame();
8989
// Body
9090

9191
while (output.getBytesRead() < targetSize ) {
@@ -94,7 +94,7 @@ public void testFlush() throws Exception {
9494
sendWindowUpdate(0, ConnectionSettingsBase.DEFAULT_INITIAL_WINDOW_SIZE);
9595
totalWindow += ConnectionSettingsBase.DEFAULT_INITIAL_WINDOW_SIZE;
9696
}
97-
parser.readFrame(true);
97+
parser.readFrame();
9898
}
9999

100100
// Check that the right number of bytes were received

test/org/apache/coyote/http2/TestAsyncTimeout.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,9 @@ public void testTimeout() throws Exception {
7979
writeFrame(frameHeader, headersPayload);
8080

8181
// Headers
82-
parser.readFrame(true);
82+
parser.readFrame();
8383
// Body
84-
parser.readFrame(true);
84+
parser.readFrame();
8585

8686
// Check that the expected text was received
8787
String trace = output.getTrace();

test/org/apache/coyote/http2/TestCancelledUpload.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ public void testCancelledRequest() throws Exception {
7575
// The connection processing thread will:
7676
// - read the request body until the flow control window is exhausted
7777
// - reset the stream if further DATA frames are received
78-
parser.readFrame(true);
78+
parser.readFrame();
7979

8080
// Check for reset and exit if found
8181
if (checkReset()) {
@@ -90,7 +90,7 @@ public void testCancelledRequest() throws Exception {
9090
"3-HeadersEnd\n",
9191
output.getTrace());
9292
output.clearTrace();
93-
parser.readFrame(true);
93+
parser.readFrame();
9494

9595
// Check for reset and exit if found
9696
if (checkReset()) {
@@ -102,7 +102,7 @@ public void testCancelledRequest() throws Exception {
102102
"3-EndOfStream\n",
103103
output.getTrace());
104104
output.clearTrace();
105-
parser.readFrame(true);
105+
parser.readFrame();
106106

107107
Assert.assertTrue(checkReset());
108108

@@ -143,7 +143,7 @@ private boolean checkReset() throws IOException, Http2Exception {
143143
return false;
144144
}
145145
output.clearTrace();
146-
parser.readFrame(true);
146+
parser.readFrame();
147147
}
148148
}
149149

test/org/apache/coyote/http2/TestFlowControl.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,11 +83,11 @@ public void testNotFound() throws Exception {
8383

8484
// Read the 404 error page
8585
// headers
86-
parser.readFrame(true);
86+
parser.readFrame();
8787
// body
88-
parser.readFrame(true);
88+
parser.readFrame();
8989
// reset (because the request body was not fully read)
90-
parser.readFrame(true);
90+
parser.readFrame();
9191

9292
// Validate response
9393
// Response size varies as error page is generated and includes version
@@ -140,7 +140,7 @@ private void waitForWindowSize(int streamId) throws Http2Exception, IOException
140140
boolean found = false;
141141
String trace;
142142
do {
143-
parser.readFrame(true);
143+
parser.readFrame();
144144
trace = output.getTrace();
145145
output.clearTrace();
146146
found = trace.startsWith(prefix);

test/org/apache/coyote/http2/TestHttp2Limits.java

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public void testSettingsOverheadLimits() throws Exception {
4949
for (int i = 0; i < 100; i++) {
5050
try {
5151
sendSettings(0, false);
52-
parser.readFrame(true);
52+
parser.readFrame();
5353
} catch (IOException ioe) {
5454
// Server closed connection before client has a chance to read
5555
// the Goaway frame. Treat this as a pass.
@@ -148,8 +148,8 @@ public void testHeaderLimits1x12kin1kChunksThenNewRequest() throws Exception {
148148

149149
output.clearTrace();
150150
sendSimpleGetRequest(5);
151-
parser.readFrame(true);
152-
parser.readFrame(true);
151+
parser.readFrame();
152+
parser.readFrame();
153153
Assert.assertEquals(getSimpleResponseTrace(5), output.getTrace());
154154
}
155155

@@ -280,7 +280,7 @@ private void doTestHeaderLimits(int headerCount, int headerSize, int maxHeaderPa
280280
}
281281
case STREAM_RESET: {
282282
// Expect a stream reset
283-
parser.readFrame(true);
283+
parser.readFrame();
284284
Assert.assertEquals("3-RST-[11]\n", output.getTrace());
285285
Assert.assertNull(e);
286286
break;
@@ -300,7 +300,7 @@ private void doTestHeaderLimits(int headerCount, int headerSize, int maxHeaderPa
300300
// Note: Some platforms will allow the read if if the write fails
301301
// above.
302302
try {
303-
parser.readFrame(true);
303+
parser.readFrame();
304304
MatcherAssert.assertThat(output.getTrace(), RegexMatcher.matchesRegex(
305305
"0-Goaway-\\[1\\]-\\[11\\]-\\[" + limitMessage + "\\]"));
306306
} catch (IOException se) {
@@ -424,21 +424,21 @@ private void doTestCookieLimit(int cookieCount, int maxCookieCount, int failMode
424424

425425
switch (failMode) {
426426
case 0: {
427-
parser.readFrame(true);
428-
parser.readFrame(true);
429-
parser.readFrame(true);
427+
parser.readFrame();
428+
parser.readFrame();
429+
parser.readFrame();
430430
System.out.println(output.getTrace());
431431
Assert.assertEquals(getCookieResponseTrace(3, cookieCount), output.getTrace());
432432
break;
433433
}
434434
case 1: {
435435
// Check status is 400
436-
parser.readFrame(true);
436+
parser.readFrame();
437437
Assert.assertTrue(output.getTrace(), output.getTrace().startsWith(
438438
"3-HeadersStart\n3-Header-[:status]-[400]"));
439439
output.clearTrace();
440440
// Check EOS followed by error page body
441-
parser.readFrame(true);
441+
parser.readFrame();
442442
Assert.assertTrue(output.getTrace(), output.getTrace().startsWith("3-EndOfStream\n3-Body-<!doctype"));
443443
break;
444444
}
@@ -505,10 +505,10 @@ private void doTestPostWithTrailerHeaders(int maxTrailerCount, int maxTrailerSiz
505505

506506
switch (failMode) {
507507
case NONE: {
508-
parser.readFrame(true);
509-
parser.readFrame(true);
510-
parser.readFrame(true);
511-
parser.readFrame(true);
508+
parser.readFrame();
509+
parser.readFrame();
510+
parser.readFrame();
511+
parser.readFrame();
512512

513513
String len = Integer.toString(256 + TRAILER_HEADER_VALUE.length());
514514

@@ -534,7 +534,7 @@ private void doTestPostWithTrailerHeaders(int maxTrailerCount, int maxTrailerSiz
534534
// the enhance your calm reset
535535
if ("3-RST-[5]\n".equals(output.getTrace())) {
536536
output.clearTrace();
537-
parser.readFrame(true);
537+
parser.readFrame();
538538
}
539539

540540
Assert.assertEquals("3-RST-[11]\n", output.getTrace());

test/org/apache/coyote/http2/TestHttp2Section_3_2.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public void testConnectionNoPreface() throws Exception {
6161
// If we don't send the preface the server should kill the connection.
6262
try {
6363
// Make the parser read something.
64-
parser.readFrame(true);
64+
parser.readFrame();
6565
} catch (IOException ioe) {
6666
// Expected because the server is going to drop the connection.
6767
}
@@ -78,7 +78,7 @@ public void testConnectionIncompletePrefaceStart() throws Exception {
7878
os.flush();
7979
try {
8080
// Make the parser read something.
81-
parser.readFrame(true);
81+
parser.readFrame();
8282
} catch (IOException ioe) {
8383
// Expected because the server is going to drop the connection.
8484
}
@@ -96,7 +96,7 @@ public void testConnectionInvalidPrefaceStart() throws Exception {
9696
os.flush();
9797
try {
9898
// Make the parser read something.
99-
parser.readFrame(true);
99+
parser.readFrame();
100100
} catch (IOException ioe) {
101101
// Expected because the server is going to drop the connection.
102102
}

0 commit comments

Comments
 (0)