Skip to content

Reset an HTTP/2 stream rather than end it short of the content-length - #1248

Open
arturobernalg wants to merge 1 commit into
apache:mainfrom
arturobernalg:h2-response-short-body
Open

arturobernalg wants to merge 1 commit into
apache:mainfrom
arturobernalg:h2-response-short-body

Conversation

@arturobernalg

Copy link
Copy Markdown
Member

RFC 9113, section 8.1.1 states that a response is malformed if the value of the content-length header field is not the sum of the DATA frame payloads.

An application that ends its response having written fewer bytes than the content length it set currently has the stream ended normally, so the client receives a truncated response that looks complete. With HTTP/1.1 the client keeps waiting for the missing bytes instead.

This resets the stream with PROTOCOL_ERROR in that case. Responses that have no body, such as those to HEAD requests, are not affected.

Checked against a running Tomcat with a raw HTTP/2 client (content-length 10, 5 bytes written): without the change the response was HEADERS, DATA(5), DATA(0, END_STREAM); with it, HEADERS, DATA(5), RST_STREAM(PROTOCOL_ERROR). A response that matches its content length, HEAD, trailers and static files behave as before. The HTTP/2 test suite passes.

RFC 9113, section 8.1.1 states that a response is malformed if the value
of the content-length header field is not the sum of the DATA frame
payloads. An application that ended its response having written fewer
bytes than the content length it had set had the stream ended normally,
so the client received a truncated response that looked complete.

Reset the stream with PROTOCOL_ERROR in that case so that the client can
tell the response is incomplete. Responses that have no body, such as
those to HEAD requests, are not affected.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant