Mentions légales du service

Skip to content
Snippets Groups Projects
Commit 92788793 authored by Luc Sarzyniec's avatar Luc Sarzyniec
Browse files

[http] Replace wget with a native ruby implementation in HTTP.fetch_file

Change-Id: I387cbef2d9e6a7e591ba11729396b7413c5119a0
parent f2e05169
No related branches found
No related tags found
1 merge request!1simplify Debian packaging
...@@ -138,12 +138,16 @@ class HTTPFetchFile < FetchFile ...@@ -138,12 +138,16 @@ class HTTPFetchFile < FetchFile
def grab(dest,dir=nil) def grab(dest,dir=nil)
begin begin
if (code = HTTP.fetch_file(@path,dest)) != 200 HTTP.fetch_file(@path,dest)
error("Unable to grab the file #{@path} (http error ##{code})")
end
nil nil
rescue KadeployError => ke rescue KadeployError => ke
raise ke raise ke
rescue KadeployHTTPError => k
error("Unable to grab the file #{@path} (http error ##{k.errno})")
rescue KadeployError => ke
raise ke
rescue Errno::ECONNREFUSED
error("Unable to grab the file #{@path} (connection refused)")
rescue Exception => e rescue Exception => e
error("Unable to grab the file #{@path} (#{e.message})") error("Unable to grab the file #{@path} (#{e.message})")
end end
......
...@@ -24,8 +24,25 @@ module HTTP ...@@ -24,8 +24,25 @@ module HTTP
# Output # Output
# * return http_response and ETag # * return http_response and ETag
def self.fetch_file(uri,destfile) def self.fetch_file(uri,destfile)
out = `LANG=C wget --server-response --no-verbose --no-check-certificate #{uri} --output-document=#{destfile} 2>&1` ret = nil
return out[/^\s*HTTP\/[0-9\.]+\s+(\d+)/,1].to_i rescue nil url = URI.parse(uri)
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = url.is_a?(URI::HTTPS)
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
http.start
http.request_get(url.path,{}) do |resp|
raise KadeployHTTPError.new(resp.code) if !resp.is_a?(Net::HTTPSuccess) and !resp.is_a?(Net::HTTPNotModified)
ret = resp.to_hash
File.open(destfile,'w+') do |f|
resp.read_body do |chunk|
f.write chunk
nil
end
end
end
return ret
end end
def self.check_file(uri, expected_etag=nil) def self.check_file(uri, expected_etag=nil)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment