From 1e7caef0a95f9f2435f73d5234f05cb2fdb62683 Mon Sep 17 00:00:00 2001 From: Yoann MOROCUTTI Date: Wed, 26 Apr 2023 10:27:28 +0200 Subject: [PATCH] fix: Use StreamContextFactory from composer package to create stream context as this method already support HTTP proxy settings [repman-http-proxy] --- src/Service/Downloader/ReactDownloader.php | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/src/Service/Downloader/ReactDownloader.php b/src/Service/Downloader/ReactDownloader.php index 5fc964e7..46b3119e 100644 --- a/src/Service/Downloader/ReactDownloader.php +++ b/src/Service/Downloader/ReactDownloader.php @@ -7,6 +7,7 @@ use Buddy\Repman\Kernel; use Buddy\Repman\Service\Downloader; use Clue\React\Mq\Queue; +use Composer\Util\StreamContextFactory; use Munus\Control\Option; use Psr\Http\Message\ResponseInterface; use React\EventLoop\Loop; @@ -39,7 +40,7 @@ public function getContents(string $url, array $headers = [], callable $notFound { $retries = 3; do { - $stream = @fopen($url, 'r', false, $this->createContext($headers)); + $stream = @fopen($url, 'r', false, $this->createContext($url, $headers)); if ($stream !== false) { return Option::some($stream); } @@ -88,15 +89,18 @@ public function run(): void * * @return resource */ - private function createContext(array $headers = []) + private function createContext(string $url, array $headers = []) { - return stream_context_create([ - 'http' => [ - 'header' => array_merge([sprintf('User-Agent: %s', $this->userAgent())], $headers), - 'follow_location' => 1, - 'max_redirects' => 20, - ], - ]); + return StreamContextFactory::getContext( + $url, + [ + 'http' => [ + 'header' => array_merge([sprintf('User-Agent: %s', $this->userAgent())], $headers), + 'follow_location' => 1, + 'max_redirects' => 20, + ], + ] + ); } private function userAgent(): string