Skip to content

Commit

Permalink
Pin Psalm and fixup issues
Browse files Browse the repository at this point in the history
  • Loading branch information
trowski committed Feb 11, 2025
1 parent 06d5a49 commit 7dfb8fb
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 28 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"phpunit/phpunit": "^9",
"leproxy/leproxy": "^0.2.2",
"revolt/event-loop-adapter-react": "^1",
"psalm/phar": "^5"
"psalm/phar": "~5.23.0"
},
"autoload": {
"psr-4": {
Expand Down
15 changes: 11 additions & 4 deletions examples/http-client-via-proxy.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,25 @@
use Amp\Http\Client\Request;
use Amp\Http\Http1\Rfc7230;
use Amp\Http\Tunnel\Http1TunnelConnector;
use Amp\Http\Tunnel\Https1TunnelConnector;
use Amp\Socket\ClientTlsContext;

require __DIR__ . '/../vendor/autoload.php';

try {
$useHttps = (bool) ($argv[1] ?? false);
$peerName = $argv[1] ?? '';

// If you need authentication, you can set a custom header (using Basic auth here)
// $connector = new Http1TunnelConnector(new SocketAddress('127.0.0.1', 5512), [
// 'proxy-authorization' => 'Basic ' . \base64_encode('user:pass'),
// ]);

// If you have a proxy accepting HTTPS connections, you need to use Https1TunnelConnector instead:
// $connector = new Https1TunnelConnector(new SocketAddress('proxy.example.com', 5512));
$socketConnector = new Http1TunnelConnector('127.0.0.1:5512');
// If you have a proxy accepting HTTPS connections, the Https1TunnelConnector must be used, providing the
// peer name to the instance of ClientTlsContext.
$socketConnector = $useHttps
? new Https1TunnelConnector('127.0.0.1:5512', new ClientTlsContext($peerName))
: new Http1TunnelConnector('127.0.0.1:5512');

$client = (new HttpClientBuilder)
->usingPool(new UnlimitedConnectionPool(new DefaultConnectionFactory($socketConnector)))
Expand All @@ -33,7 +40,7 @@
printf(
"%s %s HTTP/%s\r\n",
$request->getMethod(),
$request->getUri(),
(string) $request->getUri(),
implode('+', $request->getProtocolVersions())
);

Expand Down
2 changes: 1 addition & 1 deletion examples/http-client-via-socks5.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
printf(
"%s %s HTTP/%s\r\n",
$request->getMethod(),
$request->getUri(),
(string) $request->getUri(),
implode('+', $request->getProtocolVersions())
);

Expand Down
18 changes: 0 additions & 18 deletions psalm-baseline.xml

This file was deleted.

14 changes: 11 additions & 3 deletions psalm.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,20 @@
xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd"
findUnusedBaselineEntry="true"
findUnusedCode="true"
errorBaseline="psalm-baseline.xml"
>
<projectFiles>
<directory name="src" />
<directory name="examples"/>
<directory name="src"/>
<ignoreFiles>
<directory name="vendor" />
<directory name="vendor"/>
</ignoreFiles>
</projectFiles>

<issueHandlers>
<PossiblyUnusedMethod>
<errorLevel type="suppress">
<directory name="src"/>
</errorLevel>
</PossiblyUnusedMethod>
</issueHandlers>
</psalm>
7 changes: 6 additions & 1 deletion src/Internal/TunnelSocket.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Amp\Http\Tunnel\Internal;

use Amp\ByteStream\ReadableStreamIteratorAggregate;
use Amp\ByteStream\ResourceStream;
use Amp\Cancellation;
use Amp\ForbidCloning;
Expand All @@ -21,12 +22,15 @@
/**
* @internal
*
* @implements \IteratorAggregate<int, string>
*
* @psalm-import-type HeaderParamArrayType from HttpMessage
*/
final class TunnelSocket implements Socket
final class TunnelSocket implements Socket, \IteratorAggregate
{
use ForbidCloning;
use ForbidSerialization;
use ReadableStreamIteratorAggregate;

/**
* @internal
Expand All @@ -44,6 +48,7 @@ public static function tunnel(
$request = new Request('http://' . \str_replace('tcp://', '', $target), 'CONNECT');
$request->setHeaders($customHeaders);

$upgradedSocket = null;
$request->setUpgradeHandler(static function (Socket $socket) use (&$upgradedSocket): void {
$upgradedSocket = $socket;
});
Expand Down

0 comments on commit 7dfb8fb

Please sign in to comment.