Skip to content

Commit 810f49d

Browse files
committed
Report HTTP/2 header parsing errors earlier
1 parent 6281c57 commit 810f49d

2 files changed

Lines changed: 11 additions & 5 deletions

File tree

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

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,9 @@ protected void readHeadersFrame(int streamId, int flags, int payloadSize, ByteBu
266266

267267
swallowPayload(streamId, FrameType.HEADERS.getId(), padLength, true, buffer);
268268

269+
// Validate the headers so far
270+
hpackDecoder.getHeaderEmitter().validateHeaders();
271+
269272
if (Flags.isEndOfHeaders(flags)) {
270273
onHeadersComplete(streamId);
271274
} else {
@@ -429,6 +432,9 @@ protected void readContinuationFrame(int streamId, int flags, int payloadSize, B
429432

430433
readHeaderPayload(streamId, payloadSize, buffer);
431434

435+
// Validate the headers so far
436+
hpackDecoder.getHeaderEmitter().validateHeaders();
437+
432438
if (endOfHeaders) {
433439
headersCurrentStream = -1;
434440
onHeadersComplete(streamId);
@@ -620,11 +626,6 @@ protected void onHeadersComplete(int streamId) throws Http2Exception {
620626
Http2Error.COMPRESSION_ERROR);
621627
}
622628

623-
// Delay validation (and triggering any exception) until this point
624-
// since all the headers still have to be read if a StreamException is
625-
// going to be thrown.
626-
hpackDecoder.getHeaderEmitter().validateHeaders();
627-
628629
synchronized (output) {
629630
output.headersEnd(streamId, headersEndStream);
630631

webapps/docs/changelog.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,11 @@
182182
<code>Content-Type</code> value to improve performance by reducing
183183
repeated <code>byte[]</code> to <code>String</code> conversions. (markt)
184184
</fix>
185+
<fix>
186+
Improve error reporting to HTTP/2 clients for header processing errors
187+
by reporting problems at the end of the frame where the error was
188+
detected rather than at the end of the headers. (markt)
189+
</fix>
185190
</changelog>
186191
</subsection>
187192
<subsection name="Jasper">

0 commit comments

Comments
 (0)