Module: DRM::HttpProcs

Defined in:
lib/drm/http_procs.rb

Class Method Summary collapse

Class Method Details

.read_proc(url) ⇒ Object

produces a read_proc(length, offset) for the given HTTP url



6
7
8
9
10
11
12
13
14
15
16
# File 'lib/drm/http_procs.rb', line 6

def self.read_proc(url)
  uri = URI.parse url
  Proc.new do |length, offset|
    request = Net::HTTP::Get.new uri.path
    request.set_range(offset, length)
    response = Net::HTTP.start(uri.host, uri.port) { |http| http.request request }
    # content_range_str = nil
    # response.each_header { |key, value| content_range_str = value and break if key.downcase == 'content-range' }
    response.body
  end
end