Skip to content

fix: Packagist proxy through HTTP Proxy #646

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
fix: Use StreamContextFactory from composer package to create stream …
…context as this method already support HTTP proxy settings

[repman-http-proxy]
  • Loading branch information
Yoann MOROCUTTI committed Apr 26, 2023
commit 1e7caef0a95f9f2435f73d5234f05cb2fdb62683
22 changes: 13 additions & 9 deletions src/Service/Downloader/ReactDownloader.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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
Expand Down