Skip to content

Commit 1e7caef

Browse files
author
Yoann MOROCUTTI
committed
fix: Use StreamContextFactory from composer package to create stream context as this method already support HTTP proxy settings
[repman-http-proxy]
1 parent 069ce08 commit 1e7caef

File tree

1 file changed

+13
-9
lines changed

1 file changed

+13
-9
lines changed

src/Service/Downloader/ReactDownloader.php

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use Buddy\Repman\Kernel;
88
use Buddy\Repman\Service\Downloader;
99
use Clue\React\Mq\Queue;
10+
use Composer\Util\StreamContextFactory;
1011
use Munus\Control\Option;
1112
use Psr\Http\Message\ResponseInterface;
1213
use React\EventLoop\Loop;
@@ -39,7 +40,7 @@ public function getContents(string $url, array $headers = [], callable $notFound
3940
{
4041
$retries = 3;
4142
do {
42-
$stream = @fopen($url, 'r', false, $this->createContext($headers));
43+
$stream = @fopen($url, 'r', false, $this->createContext($url, $headers));
4344
if ($stream !== false) {
4445
return Option::some($stream);
4546
}
@@ -88,15 +89,18 @@ public function run(): void
8889
*
8990
* @return resource
9091
*/
91-
private function createContext(array $headers = [])
92+
private function createContext(string $url, array $headers = [])
9293
{
93-
return stream_context_create([
94-
'http' => [
95-
'header' => array_merge([sprintf('User-Agent: %s', $this->userAgent())], $headers),
96-
'follow_location' => 1,
97-
'max_redirects' => 20,
98-
],
99-
]);
94+
return StreamContextFactory::getContext(
95+
$url,
96+
[
97+
'http' => [
98+
'header' => array_merge([sprintf('User-Agent: %s', $this->userAgent())], $headers),
99+
'follow_location' => 1,
100+
'max_redirects' => 20,
101+
],
102+
]
103+
);
100104
}
101105

102106
private function userAgent(): string

0 commit comments

Comments
 (0)