- Implement --proxy <url> CLI option for configuring HTTP(S) or SOCKS proxy - Add proxy handling in argument parsing with proper validation - Update documentation in COMPILER_CLI.md, README.md, and README-CN.md - Enhance Downloader class to support proxy configuration for curl commands - Add stream context options for HTTP proxy with authentication support - Include proxy error message sanitization to hide sensitive information - Add unit tests for proxy functionality covering curl and stream scenarios - Update bash completion script to include new --proxy option - Validate proxy URL requirements with appropriate error messagesmaster
parent
15e17230ac
commit
e16c787f44
8 changed files with 137 additions and 7 deletions
@ -0,0 +1,68 @@ |
||||
<?php |
||||
/** |
||||
* This file is part of TypePHP(AOT). |
||||
* |
||||
* @link https://www.swoole.com/aot/ |
||||
* @contact service@swoole.com |
||||
*/ |
||||
|
||||
namespace TypePhpTest\Http; |
||||
|
||||
use PHPUnit\Framework\TestCase; |
||||
use TypePhp\Http\Downloader; |
||||
|
||||
/** |
||||
* @internal |
||||
* @coversNothing |
||||
*/ |
||||
final class DownloaderTest extends TestCase |
||||
{ |
||||
public function testProxyIsAddedToCurlDownloads(): void |
||||
{ |
||||
$downloader = new Downloader('socks5h://127.0.0.1:1080'); |
||||
|
||||
self::assertSame( |
||||
[ |
||||
'/usr/bin/curl', |
||||
'--fail', |
||||
'--location', |
||||
'--retry', |
||||
'3', |
||||
'--proxy', |
||||
'socks5h://127.0.0.1:1080', |
||||
'--output', |
||||
'/tmp/archive.tar.xz', |
||||
'https://www.php.net/archive.tar.xz', |
||||
], |
||||
$downloader->curlCommand( |
||||
'/usr/bin/curl', |
||||
'https://www.php.net/archive.tar.xz', |
||||
'/tmp/archive.tar.xz', |
||||
), |
||||
); |
||||
} |
||||
|
||||
public function testHttpProxyIsConfiguredForStreamFallback(): void |
||||
{ |
||||
$downloader = new Downloader('http://user:p%40ss@proxy.example:8080'); |
||||
|
||||
self::assertSame( |
||||
[ |
||||
'http' => [ |
||||
'timeout' => 30, |
||||
'user_agent' => 'TypePHP/tpc', |
||||
'proxy' => 'tcp://proxy.example:8080', |
||||
'request_fulluri' => true, |
||||
'header' => 'Proxy-Authorization: Basic ' . base64_encode('user:p@ss'), |
||||
], |
||||
], |
||||
$downloader->streamContextOptions(), |
||||
); |
||||
} |
||||
|
||||
public function testEmptyProxyIsRejected(): void |
||||
{ |
||||
$this->expectException(\InvalidArgumentException::class); |
||||
new Downloader(' '); |
||||
} |
||||
} |
||||
Loading…
Reference in new issue