Support multiple byte-range requests #559

Open
wants to merge 1 commit into
from

5 participants

@rakoo

As stated, support multiple byte-range requests for serving static files. The drawback is that the each method yields the headers and the \r\n after the content separately, leading in a less efficient use of the socket.

@rakoo rakoo referenced this pull request in sinatra/sinatra May 19, 2013
Open

Use Rack::File's Content-Type in send_file #714

@raggi raggi commented on the diff Jul 4, 2013
lib/rack/file.rb
return response
+ elsif @ranges.length > 1
+ # Partial content, multiple ranges
+ # load securerandom lazily
+ require 'securerandom'
@raggi
Official Rack repositories member
raggi added a line comment Jul 4, 2013

There is only really disadvantage to lazy loading this, please load it at the top.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@raggi raggi commented on the diff Jul 4, 2013
lib/rack/file.rb
return response
+ elsif @ranges.length > 1
+ # Partial content, multiple ranges
+ # load securerandom lazily
+ require 'securerandom'
+
+ @multipart_separator = "boundary-" + SecureRandom.base64
@raggi
Official Rack repositories member
raggi added a line comment Jul 4, 2013

I would love to see multipart body construction abstracted into a clean class under the multipart space in utils (which isn't that clean right now, sadly).

I'm also not convinced that there is any advantage to using random base64 here, over a static value. Can you explain the motivation?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@raggi
Official Rack repositories member

Thank you for taking the time to start this. It's been a long term TODO.

@scudelletti

@rakoo to fix the specs in Ruby <= 2.0.0 you can use something like (1..2).to_a.size.

I tried here with ruby 1.93-p448 and the method .count works, but I don't know if in 1.8.7 version it keeps working.

@raggi raggi added this to the Rack 1.6 milestone Jul 12, 2014
@raggi
Official Rack repositories member

I will merge this for 1.6 if the comments are addressed and patch is rebased.

@spastorino
Official Rack repositories member

ping @rakoo, any updates on this?

@spastorino spastorino modified the milestone: Rack 2.0, Rack 1.6 Nov 27, 2014
@spastorino
Official Rack repositories member

Changed the milestone because we are releasing an RC in a couple of hours.

@zzak

I guess this needs to be rebased :/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment