1 # -*- encoding: binary -*-
3 module Rainbows::Response::Range
4 HTTP_RANGE = 'HTTP_RANGE'
5 Content_Range = 'Content-Range'.freeze
6 Content_Length = 'Content-Length'.freeze
8 # This does not support multipart responses (does anybody actually
9 # use those?) +headers+ is always a Rack::Utils::HeaderHash
10 def make_range!(env, status, headers)
11 if 200 == status.to_i &&
12 (clen = headers[Content_Length]) &&
13 /\Abytes=(\d+-\d*|\d*-\d+)\z/ =~ env[HTTP_RANGE]
19 elsif a.empty? # bytes=-N
20 offset = clen - b.to_i
24 count = b.to_i + 1 - offset
26 raise Rainbows::Response416 if count <= 0 || offset >= clen
27 count = clen if count > clen
28 headers[Content_Length] = count.to_s
29 headers[Content_Range] = "bytes #{offset}-#{offset+count-1}/#{clen}"
30 [ status, offset, count ]