Repository navigation
Conversation
A stream longer than the declared length used to be written in full. A shorter stream was written without an error.
IO.copy_stream wrote the whole stream after the header had announced a shorter length. Copy only that many bytes, and raise ArgumentError when the stream is shorter or already has more.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #376.
send_request_with_body_streamwrote theContent-Lengthheader and thenIO.copy_streamof the whole IO. Bytes past the declared length were written on the socket. A stream shorter than the declared length was written with no error.The copy now stops at
Content-Length. If fewer bytes were available, or the stream already has another byte, this raisesArgumentError. A pipe that has not produced another byte yet is left alone, because reading it would block, and those bytes were not written. Chunked requests are unchanged: the chunk framing covers the whole stream.Before the change, a 5-byte
Content-Lengthand a longer stream wroteAAAAAplus the rest ("AAAAAGET /x HTTP/1.1\r\n\r\n"). After it, the same request raisesArgumentErrorand the socket has onlyAAAAA.ruby -Ilib:test/lib -rhelper test/net/http/test_http_request.rb: 11 tests, 44 assertions, 0 failures.