From a5b2814770f4c1a564d73b3a30ca40b86f99711a Mon Sep 17 00:00:00 2001 From: Jack Nagel Date: Wed, 30 Oct 2013 00:11:46 -0500 Subject: [PATCH] Use curl to download list of Apache mirrors Ruby's OpenURI library is somewhat broken under 1.8 and chokes on otherwise valid values of http(s)_proxy. Use curl to get the mirror list instead. Fixes Homebrew/homebrew#23708. --- Library/Homebrew/download_strategy.rb | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/Library/Homebrew/download_strategy.rb b/Library/Homebrew/download_strategy.rb index acbb23e549..d17f39ce61 100644 --- a/Library/Homebrew/download_strategy.rb +++ b/Library/Homebrew/download_strategy.rb @@ -1,4 +1,3 @@ -require 'open-uri' require 'utils/json' require 'erb' @@ -208,8 +207,26 @@ end # Detect and download from Apache Mirror class CurlApacheMirrorDownloadStrategy < CurlDownloadStrategy + def apache_mirrors + rd, wr = IO.pipe + buf = "" + + pid = fork do + rd.close + $stdout.reopen(wr) + $stderr.reopen(wr) + curl "#{@url}&asjson=1" + end + wr.close + + buf << rd.read until rd.eof? + rd.close + Process.wait(pid) + buf + end + def _fetch - mirrors = Utils::JSON.load(open("#{@url}&asjson=1").read) + mirrors = Utils::JSON.load(apache_mirrors) url = mirrors.fetch('preferred') + mirrors.fetch('path_info') ohai "Best Mirror #{url}"