curl - Ruby CGI is unable to continue the downloading process when sending data to Opera -


i wrote small ruby cgi script - let's call downloader.rb - friends download files file hosting service. script looks follows:

#!/usr/bin/ruby  require "cgi"  cgi=cgi.new(:accept_charset => "utf-8") file_id=cgi["id"] #get file id request variable url="http://www.yetanotherfilehost.com/file/#{file_id}"  range=env["http_range"]==nil ? "" : "-r #{env["http_range"].split("=")[1]}" #get range http request header in fact passed in request header, can accessed through environment variable called http_range  header=%x{curl #{range} -s -b ./cookie.txt "#{url}" -l -i}.force_encoding("utf-8").encode("utf-8").split("\r\n").last(7).join("\r\n") #i call curl option -i dump response headers , -l # follow redirection occurs in case, , keeping  # last 7 lines of headers, send them later users,  # emulating download process. response headers looks follows:  =begin  http/1.1 302 found date: sat, 20 jun 2015 06:25:19 gmt server: apache expires: thu, 19 nov 1981 08:52:00 gmt cache-control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0 pragma: no-cache set-cookie: auth=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx; expires=sun, 20-dec-2015 07:25:19 gmt; path=/; domain=.yetanotherfilehost.com location: http://server007.yetanotherfilehost.com/get/p/33fi3trctwtl/c50fc7dbb8824cfe/gandahar.avi connection: close content-type: text/html; charset=utf-8  http/1.1 200 ok server: nginx date: sat, 20 jun 2015 06:25:20 gmt *content-type: application/force-download *content-length: 1468299264 *last-modified: fri, 12 sep 2014 11:43:06 gmt *connection: close *content-disposition: attachment; filename="gandahar.avi" *etag: "5412dc4a-57847800" *accept-ranges: bytes  =end  puts header # sending last 7 lines of headers marked asterisks, users. puts system "curl #{range} -s -b ./cookie.txt \"#{ff_url}\" -l -o -" #download file , writing content stdout 

they can use script example calling pasting such link in browsers: http://www.example.com/cgi-bin/downloader.rb?id=33fi3trctwtl , downloading begins, thx supported cookie file.

my problem is, when use curl or wget download files, able continue downloading after interrupt pressing ctrl+c (for example "curl -c - http://www.example.com/cgi-bin/downloader.rb?id=33fi3trctwtl" or "wget -c http://www.example.com/cgi-bin/downloader.rb?id=33fi3trctwtl" ) both program can continue downloading process, , files intact according md5 sums. when using opera browser download files , stop downloading process, unable continue them. can make work opera , of course other browsers has ability continue interrupted downloads?

okay, problem solved. had add header line @ first place called: "status: 206 partial content", when range request header isn't empty.


Comments

Popular posts from this blog

powershell Start-Process exit code -1073741502 when used with Credential from a windows service environment -

twig - Using Twigbridge in a Laravel 5.1 Package -

c# - LINQ join Entities from HashSet's, Join vs Dictionary vs HashSet performance -