def handle_range_request!(length)
      if Rack.release >= "2.0"
        ranges = Rack::Utils.get_byte_ranges(request.headers["Range"], length)
      else
        ranges = Rack::Utils.byte_ranges(request.env, length)
      end

      # we support ranged requests
      response.headers["Accept-Ranges"] = "bytes"

      if ranges.nil? || ranges.length > 1
        # no ranges, or multiple ranges (which we don't support)
        response.status = 200
        range = 0..length-1
      elsif ranges.empty?
        # unsatisfiable range
        response.headers["Content-Range"] = "bytes */#{length}"
        error!(416, "Byte range unsatisfiable")
      else
        range = ranges[0]
        response.status = 206
        response.headers["Content-Range"] = "bytes #{range.begin}-#{range.end}/#{length}"
      end

      response.headers["Content-Length"] = range.size.to_s

      range
    end
def handle_range_request!(length)
      if Rack.release >= "2.0"
        ranges = Rack::Utils.get_byte_ranges(request.headers["Range"], length)
      else
        ranges = Rack::Utils.byte_ranges(request.env, length)
      end

      # we support ranged requests
      response.headers["Accept-Ranges"] = "bytes"

      if ranges.nil? || ranges.length > 1
        # no ranges, or multiple ranges (which we don't support)
        response.status = 200
        range = 0..length-1
      elsif ranges.empty?
        # unsatisfiable range
        response.headers["Content-Range"] = "bytes */#{length}"
        error!(416, "Byte range unsatisfiable")
      else
        range = ranges[0]
        response.status = 206
        response.headers["Content-Range"] = "bytes #{range.begin}-#{range.end}/#{length}"
      end

      response.headers["Content-Length"] = range.size.to_s

      range
    end
Handles partial responses requested in the "Range" header. Implementation
 is mostly copied from Rack::File.