Skip to content

Commit

Permalink
Use curl to download list of Apache mirrors
Browse files Browse the repository at this point in the history
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#23708.
  • Loading branch information
jacknagel committed Oct 30, 2013
1 parent e67dd59 commit ce72980
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions Library/Homebrew/download_strategy.rb
@@ -1,4 +1,3 @@
require 'open-uri'
require 'utils/json'
require 'erb'

Expand Down Expand Up @@ -208,8 +207,26 @@ def ext

# 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}"
Expand Down

0 comments on commit ce72980

Please sign in to comment.