Resuming file downloads in Ruby, range header issue

二次信任 提交于 2019-12-12 03:49:08

问题


When setting a range header in Ruby 1.8.7, an additional "X-REMOVED: Range" header is being added, which (seemingly) prevents download resumes from working.

size = File.size(local_file)
Net::HTTP.start(domain) do |http|
  headers = { 
    'Range' => "bytes=#{size}-"
  }
  resp = http.get(remote_file, headers)
  open(local_file, "wb") do |file|
    file.write(resp.body)
  end
end

Header sent:

GET /test.zip HTTP/1.1..Host: 192.168.50.1..Accept: */*..X-REMOVED: Range..Range: bytes=481-....

I've also tried using set_range with the same result.


回答1:


Well this is embarrassing. The resumes not working had nothing to do with the range header. It's just that I was opening the file with "wb" instead of "ab".



来源:https://stackoverflow.com/questions/12464761/resuming-file-downloads-in-ruby-range-header-issue

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!