5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
|
# File 'lib/tasks/remote_file_loader.rb', line 5
def fetch(location, limit = 10)
uri = URI.parse(location)
raise UsageError.new("The RemoteFileTask can only handle HTTP requests at this time, it seems you were trying: #{uri.scheme}") if uri.scheme != 'http'
raise UsageError.new('HTTP redirect too deep') if limit == 0
response = nil
t = Thread.new {
response = Net::HTTP.get_response(uri.host, uri.path)
}
print(">> Downloading")
while t.alive?
print(".")
$stdout.flush
sleep(0.2)
end
puts ""
if(response.is_a? Net::HTTPSuccess)
return response
elsif(response.is_a? Net::HTTPRedirection)
return fetch(response['location'], limit - 1)
else
if(response.nil?)
raise UsageError.new("Network connection failed!")
else
puts response.to_s
return response.error!
end
end
end
|