Skip to content

Commit 40ecb8f

Browse files
committed
Update proxy examples to use simplified APIs thanks to default loop
1 parent 8a0fd7c commit 40ecb8f

5 files changed

+21
-27
lines changed

README.md

+4-10
Original file line numberDiff line numberDiff line change
@@ -598,10 +598,7 @@ to HTTPS port`443` only, this can technically be used to tunnel any TCP/IP-based
598598
protocol, such as plain HTTP and TLS-encrypted HTTPS.
599599

600600
```php
601-
$proxy = new Clue\React\HttpProxy\ProxyConnector(
602-
'http://127.0.0.1:8080',
603-
new React\Socket\Connector()
604-
);
601+
$proxy = new Clue\React\HttpProxy\ProxyConnector('127.0.0.1:8080');
605602

606603
$connector = new React\Socket\Connector(array(
607604
'tcp' => $proxy,
@@ -611,7 +608,7 @@ $connector = new React\Socket\Connector(array(
611608
$browser = new React\Http\Browser($connector);
612609
```
613610

614-
See also the [HTTP CONNECT proxy example](examples/11-client-http-connect-proxy.php).
611+
See also the [HTTP proxy example](examples/11-client-http-proxy.php).
615612

616613
### SOCKS proxy
617614

@@ -625,10 +622,7 @@ address (anonymity) or to circumvent address blocking (geoblocking). While many
625622
only, this can technically be used to tunnel any TCP/IP-based protocol.
626623

627624
```php
628-
$proxy = new Clue\React\Socks\Client(
629-
'socks://127.0.0.1:1080',
630-
new React\Socket\Connector()
631-
);
625+
$proxy = new Clue\React\Socks\Client('127.0.0.1:1080');
632626

633627
$connector = new React\Socket\Connector(array(
634628
'tcp' => $proxy,
@@ -657,7 +651,7 @@ from the outside (database behind firewall) and as such can also be used for
657651
plain HTTP and TLS-encrypted HTTPS.
658652

659653
```php
660-
$proxy = new Clue\React\SshProxy\SshSocksConnector('me@localhost:22', Loop::get());
654+
$proxy = new Clue\React\SshProxy\SshSocksConnector('[email protected]');
661655

662656
$connector = new React\Socket\Connector(array(
663657
'tcp' => $proxy,

composer.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,9 @@
3838
},
3939
"require-dev": {
4040
"clue/block-react": "^1.1",
41-
"clue/http-proxy-react": "^1.3",
42-
"clue/reactphp-ssh-proxy": "^1.0",
43-
"clue/socks-react": "^1.0",
41+
"clue/http-proxy-react": "^1.7",
42+
"clue/reactphp-ssh-proxy": "^1.3",
43+
"clue/socks-react": "^1.3",
4444
"phpunit/phpunit": "^9.3 || ^5.7 || ^4.8.35"
4545
},
4646
"autoload": {

examples/11-client-http-connect-proxy.php examples/11-client-http-proxy.php

+4-5
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,17 @@
33
// not already running a HTTP CONNECT proxy server?
44
// Try LeProxy.org or this:
55
//
6-
// $ php examples/72-server-http-connect-proxy.php 8080
7-
// $ php examples/11-client-http-connect-proxy.php
6+
// $ php examples/72-server-http-connect-proxy.php 127.0.0.1:8080
7+
// $ http_proxy=127.0.0.1:8080 php examples/11-client-http-connect-proxy.php
88

9-
use Clue\React\HttpProxy\ProxyConnector as HttpConnectClient;
109
use Psr\Http\Message\ResponseInterface;
1110
use React\Http\Browser;
1211
use React\Socket\Connector;
1312

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

16-
// create a new HTTP CONNECT proxy client which connects to a HTTP CONNECT proxy server listening on localhost:8080
17-
$proxy = new HttpConnectClient('127.0.0.1:8080', new Connector());
15+
// create a new HTTP CONNECT proxy client which connects to a HTTP CONNECT proxy server listening on 127.0.0.1:8080
16+
$proxy = new Clue\React\HttpProxy\ProxyConnector(getenv('http_proxy') ?: '127.0.0.1:8080');
1817

1918
// create a Browser object that uses the HTTP CONNECT proxy client for connections
2019
$connector = new Connector(array(

examples/12-client-socks-proxy.php

+6-4
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,19 @@
11
<?php
22

33
// not already running a SOCKS proxy server?
4-
// Try LeProxy.org or this: `ssh -D 1080 localhost`
4+
// Try LeProxy.org or this:
5+
//
6+
// $ ssh -D 1080 [email protected]
7+
// $ socks_proxy=127.0.0.1:1080 php examples/12-client-socks-proxy.php
58

6-
use Clue\React\Socks\Client as SocksClient;
79
use Psr\Http\Message\ResponseInterface;
810
use React\Http\Browser;
911
use React\Socket\Connector;
1012

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

13-
// create a new SOCKS proxy client which connects to a SOCKS proxy server listening on localhost:1080
14-
$proxy = new SocksClient('127.0.0.1:1080', new Connector());
15+
// create a new SOCKS proxy client which connects to a SOCKS proxy server listening on 127.0.0.1:1080
16+
$proxy = new Clue\React\Socks\Client(getenv('socks_proxy') ?: '127.0.0.1:1080');
1517

1618
// create a Browser object that uses the SOCKS proxy client for connections
1719
$connector = new Connector(array(

examples/13-client-ssh-proxy.php

+4-5
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
11
<?php
22

3-
use Clue\React\SshProxy\SshSocksConnector;
3+
// $ [email protected] php examples/13-client-ssh-proxy.php
4+
45
use Psr\Http\Message\ResponseInterface;
5-
use React\EventLoop\Loop;
66
use React\Http\Browser;
77
use React\Socket\Connector;
88

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

11-
// create a new SSH proxy client which connects to a SSH server listening on localhost:22
12-
// You can pass any SSH server address as first argument, e.g. [email protected]
13-
$proxy = new SshSocksConnector(isset($argv[1]) ? $argv[1] : 'localhost:22', Loop::get());
11+
// create a new SSH proxy client which connects to a SSH server listening on alice@localhost
12+
$proxy = new Clue\React\SshProxy\SshSocksConnector(getenv('ssh_proxy') ?: 'alice@localhost');
1413

1514
// create a Browser object that uses the SSH proxy client for connections
1615
$connector = new Connector(array(

0 commit comments

Comments
 (0)