Skip to content

Commit 4652b27

Browse files
author
Cursor
committed
Fix PHP proxy test failures with ProxyMesh host-only PROXY_URL.
Add amphp/http-tunnel and wire Amp through a tunnel-backed connection pool, update streams proxy request mode for HTTPS tunneling, and commit composer.lock for reproducible PHP test runs. Made-with: Cursor
1 parent 8179250 commit 4652b27

4 files changed

Lines changed: 2936 additions & 7 deletions

File tree

php/amphp_proxy.php

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,9 @@
1616

1717
use Amp\Http\Client\HttpClientBuilder;
1818
use Amp\Http\Client\Request;
19+
use Amp\Http\Client\Connection\DefaultConnectionFactory;
20+
use Amp\Http\Client\Connection\UnlimitedConnectionPool;
1921
use Amp\Http\Tunnel\Http1TunnelConnector;
20-
use Amp\Socket\SocketAddress;
2122

2223
$proxyUrl = get_proxy_url();
2324

@@ -28,12 +29,16 @@
2829
$proxyPort = $parsedProxy['port'] ?? 8080;
2930

3031
try {
31-
$connector = new Http1TunnelConnector(
32-
new SocketAddress($proxyHost, $proxyPort)
33-
);
32+
$tunnelHeaders = [];
33+
if (isset($parsedProxy['user'])) {
34+
$credentials = $parsedProxy['user'] . ':' . ($parsedProxy['pass'] ?? '');
35+
$tunnelHeaders['Proxy-Authorization'] = 'Basic ' . base64_encode($credentials);
36+
}
37+
$connector = new Http1TunnelConnector("{$proxyHost}:{$proxyPort}", $tunnelHeaders);
38+
$pool = new UnlimitedConnectionPool(new DefaultConnectionFactory($connector));
3439

3540
$client = (new HttpClientBuilder())
36-
->usingPool($connector)
41+
->usingPool($pool)
3742
->build();
3843

3944
$request = new Request($testUrl);

php/composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010
"php-http/guzzle7-adapter": "^1.0",
1111
"nyholm/psr7": "^1.8",
1212
"kriswallsmith/buzz": "^1.2",
13-
"amphp/http-client": "^5.0"
13+
"amphp/http-client": "^5.0",
14+
"amphp/http-tunnel": "^2.0"
1415
},
1516
"autoload": {
1617
"psr-4": {

0 commit comments

Comments
 (0)