|
7 | 7 | use Buddy\Repman\Kernel;
|
8 | 8 | use Buddy\Repman\Service\Downloader;
|
9 | 9 | use Clue\React\Mq\Queue;
|
| 10 | +use Composer\Util\StreamContextFactory; |
10 | 11 | use Munus\Control\Option;
|
11 | 12 | use Psr\Http\Message\ResponseInterface;
|
12 | 13 | use React\EventLoop\Loop;
|
@@ -39,7 +40,7 @@ public function getContents(string $url, array $headers = [], callable $notFound
|
39 | 40 | {
|
40 | 41 | $retries = 3;
|
41 | 42 | do {
|
42 |
| - $stream = @fopen($url, 'r', false, $this->createContext($headers)); |
| 43 | + $stream = @fopen($url, 'r', false, $this->createContext($url, $headers)); |
43 | 44 | if ($stream !== false) {
|
44 | 45 | return Option::some($stream);
|
45 | 46 | }
|
@@ -88,15 +89,18 @@ public function run(): void
|
88 | 89 | *
|
89 | 90 | * @return resource
|
90 | 91 | */
|
91 |
| - private function createContext(array $headers = []) |
| 92 | + private function createContext(string $url, array $headers = []) |
92 | 93 | {
|
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 | + ); |
100 | 104 | }
|
101 | 105 |
|
102 | 106 | private function userAgent(): string
|
|
0 commit comments