Skip to content

Commit 0cac540

Browse files
committed
Report HTTP/2 header parsing errors earlier
1 parent b5ab2fb commit 0cac540

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
@@ -265,6 +265,9 @@ private void readHeadersFrame(int streamId, int flags, int payloadSize) throws H
265265

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

268+
// Validate the headers so far
269+
hpackDecoder.getHeaderEmitter().validateHeaders();
270+
268271
if (Flags.isEndOfHeaders(flags)) {
269272
onHeadersComplete(streamId);
270273
} else {
@@ -405,6 +408,9 @@ private void readContinuationFrame(int streamId, int flags, int payloadSize) thr
405408

406409
readHeaderPayload(streamId, payloadSize);
407410

411+
// Validate the headers so far
412+
hpackDecoder.getHeaderEmitter().validateHeaders();
413+
408414
if (endOfHeaders) {
409415
headersCurrentStream = -1;
410416
onHeadersComplete(streamId);
@@ -576,11 +582,6 @@ private void onHeadersComplete(int streamId) throws Http2Exception {
576582
Http2Error.COMPRESSION_ERROR);
577583
}
578584

579-
// Delay validation (and triggering any exception) until this point
580-
// since all the headers still have to be read if a StreamException is
581-
// going to be thrown.
582-
hpackDecoder.getHeaderEmitter().validateHeaders();
583-
584585
output.headersEnd(streamId, headersEndStream);
585586

586587
if (headersEndStream) {

webapps/docs/changelog.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,11 @@
165165
<code>Content-Type</code> value to improve performance by reducing
166166
repeated <code>byte[]</code> to <code>String</code> conversions. (markt)
167167
</fix>
168+
<fix>
169+
Improve error reporting to HTTP/2 clients for header processing errors
170+
by reporting problems at the end of the frame where the error was
171+
detected rather than at the end of the headers. (markt)
172+
</fix>
168173
</changelog>
169174
</subsection>
170175
<subsection name="Jasper">

0 commit comments

Comments
 (0)