From 1471b41ba8afdec5b30da2b0e244d47da8261ef2 Mon Sep 17 00:00:00 2001 From: Jordan Alliot Date: Thu, 5 Jan 2012 11:40:11 +0100 Subject: [PATCH 1/2] Handle system proxy in file downloads --- src/Composer/Downloader/FileDownloader.php | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/Composer/Downloader/FileDownloader.php b/src/Composer/Downloader/FileDownloader.php index 7d408eed0..a96e64f1e 100644 --- a/src/Composer/Downloader/FileDownloader.php +++ b/src/Composer/Downloader/FileDownloader.php @@ -59,7 +59,22 @@ abstract class FileDownloader implements DownloaderInterface } } - copy($url, $fileName); + // Handle system proxy + if (isset($_SERVER['HTTP_PROXY'])) { + // http(s):// is not supported in proxy + $proxy = str_replace(array('http://', 'https://'), array('tcp://', 'ssl://'), $_SERVER['HTTP_PROXY']); + + $ctx = stream_context_create(array( + 'http' => array( + 'proxy' => $proxy, + 'request_fulluri' => true, + ), + )); + + copy($url, $filename, $ctx); + } else { + copy($url, $fileName); + } if (!file_exists($fileName)) { throw new \UnexpectedValueException($url.' could not be saved to '.$fileName.', make sure the' From 3444bdae821fa363d4059432bdf5bfded8ceff05 Mon Sep 17 00:00:00 2001 From: Jordan Alliot Date: Thu, 5 Jan 2012 11:58:49 +0100 Subject: [PATCH 2/2] Check openssl extension for proxy --- src/Composer/Downloader/FileDownloader.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/Composer/Downloader/FileDownloader.php b/src/Composer/Downloader/FileDownloader.php index a96e64f1e..aeb655be4 100644 --- a/src/Composer/Downloader/FileDownloader.php +++ b/src/Composer/Downloader/FileDownloader.php @@ -64,6 +64,10 @@ abstract class FileDownloader implements DownloaderInterface // http(s):// is not supported in proxy $proxy = str_replace(array('http://', 'https://'), array('tcp://', 'ssl://'), $_SERVER['HTTP_PROXY']); + if (0 === strpos($proxy, 'ssl:') && !extension_loaded('openssl')) { + throw new \RuntimeException('You must enable the openssl extension to use a proxy over https'); + } + $ctx = stream_context_create(array( 'http' => array( 'proxy' => $proxy,