Permalink
Browse files

Avoid relying on $1 for setting Content-Range header, as its value mi…

…ght be lost. Makes test pass.
  • Loading branch information...
1 parent 480b1e8 commit 44ab0902e36e61d2fc9ef92810a908d1d01b1fd6 @rkh rkh committed Oct 10, 2010
Showing with 3 additions and 3 deletions.
  1. +3 −3 lib/sinatra/base.rb
View
@@ -162,12 +162,12 @@ def send_file(path, opts={})
response['Content-Disposition'] = 'inline'
end
sf = StaticFile.open(path, 'rb')
- if (env['HTTP_RANGE'] =~ /^bytes=(\d+-\d+(?:,\d+-\d+)*)$/)
- sf.ranges = $1.split(',').collect{|range| range.split('-').collect{|n| n.to_i}}
+ if m = /^bytes=(\d+-\d+(?:,\d+-\d+)*)$/.match(env['HTTP_RANGE'])
+ sf.ranges = m[1].split(',').collect{|range| range.split('-').collect{|n| n.to_i}}
sf.ranges.each do |range|
halt 416 if range[1] < range[0]
end
- response['Content-Range'] = "bytes #{$1}/#{response['Content-Length']}"
+ response['Content-Range'] = "bytes #{m[1]}/#{response['Content-Length']}"
response['Content-Length'] = sf.ranges.dup.inject(0){|total,range| total + range[1] - range[0] + 1 }.to_s
halt 206, sf
else

0 comments on commit 44ab090

Please sign in to comment.