问题
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