Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updates the download method to follow recursively the redirects #105

Merged
merged 3 commits into from
Jan 25, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion lib/logstash/devutils/rake/vendor.rake
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,28 @@ ensure
fd.close if fd
end

def download(url, output)
def download(url, output, redirect_hops = 1)
uri = URI(url)
digest = Digest::SHA1.new
tmp = "#{output}.tmp"
Net::HTTP.start(uri.host, uri.port, :use_ssl => (uri.scheme == "https")) do |http|
request = Net::HTTP::Get.new(uri.path)
http.request(request) do |response|
fail "HTTP fetch failed for #{url}. #{response}" if [200, 301].include?(response.code)
case response
when Net::HTTPRedirection then
location = response['location']
when Net::HTTPFound then
location = response['location']
end
andsel marked this conversation as resolved.
Show resolved Hide resolved

if location
fail "Too many redirects to follow" if redirect_hops < 0
puts "Follow redirect to: #{location}"
download(location, output, redirect_hops - 1)
return
end

size = (response["content-length"].to_i || -1).to_f
count = 0
File.open(tmp, "w") do |fd|
Expand Down