Repository navigation
Support endless ranges in HTTPHeader#set_range - #390
Open
mokshupadhyay wants to merge 1 commit into
Open
mokshupadhyay wants to merge 1 commit into
mokshupadhyay wants to merge 1 commit into
Conversation
req.range = (100..) raised NoMethodError because Range#end is nil. Treat it like 100..-1 and send "bytes=100-". Also send "bytes=0-" for 0..-1; it was sent as "bytes=-0", a zero-length suffix that no server can satisfy.
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.
Net::HTTPHeader#set_range(alsorange=) builds aRangerequest header from a RubyRange. It has two bugs:(100..)crashes, becauseRange#endisniland the code then evaluatesnil < .../last -= 1.0..-1("the whole content") is sent asbytes=-0, a suffix range of length zero, which can never be satisfied. The check isfirst > 0 ? "#{first}-" : "-#{-first}", which treats0like a negative number.Real header produced for
req.range = ronmasterand with this change:5..NoMethodError: undefined method '<' for nilbytes=5-10..NoMethodErrorbytes=10-0..-1bytes=-0bytes=0-5..-1bytes=5-bytes=5-0..9,1...5,-3..-1bytes=0-9,bytes=1-4,bytes=-3The fix treats an endless range like
first..-1(runs to the end of the content) and usesfirst >= 0for the open-ended form. TheNet::HTTPHeader#rangegetter already readsbytes=1-back as1..-1, so this matches the existing behaviour in the other direction.Test:
test_range_endlessintest/net/http/test_httpheader.rb(100..,100...,0..,-5..and0..-1); it errors onmasterand passes now.rake testpasses (224 tests, 994 assertions). No rubocop config in the repo. Not covered: beginless ranges, which I did not change. I did not check which Ruby release bundles the current version of this gem.