@@ -72,16 +72,19 @@ secure HTTPS request to google.com through a local HTTP proxy server:
7272``` php
7373$loop = React\EventLoop\Factory::create();
7474
75- $proxy = new ProxyConnector('127.0.0.1:8080', new Connector($loop));
76- $connector = new Connector($loop, array(
75+ $proxy = new Clue\React\HttpProxy\ProxyConnector(
76+ '127.0.0.1:8080',
77+ new React\Socket\Connector($loop)
78+ );
79+ $connector = new React\Socket\Connector($loop, array(
7780 'tcp' => $proxy,
7881 'timeout' => 3.0,
7982 'dns' => false
8083));
8184
82- $connector->connect('tls://google.com:443')->then(function (ConnectionInterface $stream ) {
83- $stream ->write("GET / HTTP/1.1\r\nHost: google.com\r\nConnection: close\r\n\r\n");
84- $stream ->on('data', function ($chunk) {
85+ $connector->connect('tls://google.com:443')->then(function (React\Socket\ ConnectionInterface $connection ) {
86+ $connection ->write("GET / HTTP/1.1\r\nHost: google.com\r\nConnection: close\r\n\r\n");
87+ $connection ->on('data', function ($chunk) {
8588 echo $chunk;
8689 });
8790}, 'printf');
@@ -106,8 +109,8 @@ Its constructor simply accepts an HTTP proxy URL and a connector used to connect
106109to the proxy server address:
107110
108111``` php
109- $connector = new Connector($loop);
110- $proxy = new ProxyConnector('http://127.0.0.1:8080', $connector);
112+ $connector = new React\Socket\ Connector($loop);
113+ $proxy = new Clue\React\HttpProxy\ ProxyConnector('http://127.0.0.1:8080', $connector);
111114```
112115
113116The proxy URL may or may not contain a scheme and port definition. The default
@@ -133,9 +136,9 @@ This makes it fairly simple to add HTTP CONNECT proxy support to pretty much any
133136higher-level component:
134137
135138``` diff
136- - $client = new SomeClient ($connector);
137- + $proxy = new ProxyConnector('http://127.0.0.1:8080', $connector);
138- + $client = new SomeClient ($proxy);
139+ - $acme = new AcmeApi ($connector);
140+ + $proxy = new Clue\React\HttpProxy\ ProxyConnector('http://127.0.0.1:8080', $connector);
141+ + $acme = new AcmeApi ($proxy);
139142```
140143
141144#### Plain TCP connections
@@ -147,11 +150,14 @@ As documented above, you can simply invoke its `connect()` method to establish
147150a streaming plain TCP/IP connection and use any higher level protocol like so:
148151
149152``` php
150- $proxy = new ProxyConnector('http://127.0.0.1:8080', $connector);
153+ $proxy = new Clue\React\HttpProxy\ProxyConnector(
154+ '127.0.0.1:8080',
155+ new React\Socket\Connector($loop)
156+ );
151157
152- $proxy->connect('tcp://smtp.googlemail.com:587')->then(function (ConnectionInterface $stream ) {
153- $stream ->write("EHLO local\r\n");
154- $stream ->on('data', function ($chunk) use ($stream ) {
158+ $proxy->connect('tcp://smtp.googlemail.com:587')->then(function (React\Socket\ ConnectionInterface $connection ) {
159+ $connection ->write("EHLO local\r\n");
160+ $connection ->on('data', function ($chunk) use ($connection ) {
155161 echo $chunk;
156162 });
157163});
@@ -161,14 +167,19 @@ You can either use the `ProxyConnector` directly or you may want to wrap this co
161167in ReactPHP's [ ` Connector ` ] ( https://github.com/reactphp/socket#connector ) :
162168
163169``` php
164- $connector = new Connector($loop, array(
170+ $proxy = new Clue\React\HttpProxy\ProxyConnector(
171+ '127.0.0.1:8080',
172+ new React\Socket\Connector($loop)
173+ );
174+
175+ $connector = new React\Socket\Connector($loop, array(
165176 'tcp' => $proxy,
166177 'dns' => false
167178));
168179
169- $connector->connect('tcp://smtp.googlemail.com:587')->then(function (ConnectionInterface $stream ) {
170- $stream ->write("EHLO local\r\n");
171- $stream ->on('data', function ($chunk) use ($stream ) {
180+ $connector->connect('tcp://smtp.googlemail.com:587')->then(function (React\Socket\ ConnectionInterface $connection ) {
181+ $connection ->write("EHLO local\r\n");
182+ $connection ->on('data', function ($chunk) use ($connection ) {
172183 echo $chunk;
173184 });
174185});
@@ -186,15 +197,19 @@ ReactPHP's [`Connector`](https://github.com/reactphp/socket#connector) or the
186197low-level [ ` SecureConnector ` ] ( https://github.com/reactphp/socket#secureconnector ) :
187198
188199``` php
189- $proxy = new ProxyConnector('http://127.0.0.1:8080', $connector);
190- $connector = new Connector($loop, array(
200+ $proxy = new Clue\React\HttpProxy\ProxyConnector(
201+ '127.0.0.1:8080',
202+ new React\Socket\Connector($loop)
203+ );
204+
205+ $connector = new React\Socket\Connector($loop, array(
191206 'tcp' => $proxy,
192207 'dns' => false
193208));
194209
195- $connector->connect('tls://smtp.googlemail.com:465')->then(function (ConnectionInterface $stream ) {
196- $stream ->write("EHLO local\r\n");
197- $stream ->on('data', function ($chunk) use ($stream ) {
210+ $connector->connect('tls://smtp.googlemail.com:465')->then(function (React\Socket\ ConnectionInterface $connection ) {
211+ $connection ->write("EHLO local\r\n");
212+ $connection ->on('data', function ($chunk) use ($connection ) {
198213 echo $chunk;
199214 });
200215});
@@ -213,7 +228,7 @@ This allows you to send both plain HTTP and TLS-encrypted HTTPS requests like th
213228
214229``` php
215230$proxy = new Clue\React\HttpProxy\ProxyConnector(
216- 'http:// 127.0.0.1:8080',
231+ '127.0.0.1:8080',
217232 new React\Socket\Connector($loop)
218233);
219234
@@ -252,13 +267,18 @@ It provides the same `connect()` method, but will automatically reject the
252267underlying connection attempt if it takes too long:
253268
254269``` php
255- $connector = new Connector($loop, array(
270+ $proxy = new Clue\React\HttpProxy\ProxyConnector(
271+ '127.0.0.1:8080',
272+ new React\Socket\Connector($loop)
273+ );
274+
275+ $connector = new React\Socket\Connector($loop, array(
256276 'tcp' => $proxy,
257277 'dns' => false,
258278 'timeout' => 3.0
259279));
260280
261- $connector->connect('tcp://google.com:80')->then(function ($stream ) {
281+ $connector->connect('tcp://google.com:80')->then(function ($connection ) {
262282 // connection succeeded within 3.0 seconds
263283});
264284```
@@ -294,7 +314,12 @@ Given that remote DNS resolution is assumed to be the preferred mode, all
294314other examples explicitly disable DNS resolution like this:
295315
296316``` php
297- $connector = new Connector($loop, array(
317+ $proxy = new Clue\React\HttpProxy\ProxyConnector(
318+ '127.0.0.1:8080',
319+ new React\Socket\Connector($loop)
320+ );
321+
322+ $connector = new React\Socket\Connector($loop, array(
298323 'tcp' => $proxy,
299324 'dns' => false
300325));
@@ -303,8 +328,13 @@ $connector = new Connector($loop, array(
303328If you want to explicitly use * local DNS resolution* , you can use the following code:
304329
305330``` php
331+ $proxy = new Clue\React\HttpProxy\ProxyConnector(
332+ '127.0.0.1:8080',
333+ new React\Socket\Connector($loop)
334+ );
335+
306336// set up Connector which uses Google's public DNS (8.8.8.8)
307- $connector = new Connector($loop, array(
337+ $connector = new React\Socket\ Connector($loop, array(
308338 'tcp' => $proxy,
309339 'dns' => '8.8.8.8'
310340));
@@ -319,7 +349,10 @@ If your HTTP proxy server requires authentication, you may pass the username and
319349password as part of the HTTP proxy URL like this:
320350
321351``` php
322- $proxy = new ProxyConnector('http://user:pass@127.0.0.1:8080', $connector);
352+ $proxy = new Clue\React\HttpProxy\ProxyConnector(
353+ 'http://user:pass@127.0.0.1:8080',
354+ new React\Socket\Connector($loop)
355+ );
323356```
324357
325358Note that both the username and password must be percent-encoded if they contain
@@ -329,7 +362,7 @@ special characters:
329362$user = 'he:llo';
330363$pass = 'p@ss';
331364
332- $proxy = new ProxyConnector(
365+ $proxy = new Clue\React\HttpProxy\ ProxyConnector(
333366 rawurlencode($user) . ':' . rawurlencode($pass) . '@127.0.0.1:8080',
334367 $connector
335368);
@@ -353,10 +386,14 @@ in practice, but may be useful for some more advanced use cases. In this case,
353386you may simply pass an assoc array of additional request headers like this:
354387
355388``` php
356- $proxy = new ProxyConnector('127.0.0.1:8080', $connector, array(
357- 'Proxy-Authorization' => 'Bearer abc123',
358- 'User-Agent' => 'ReactPHP'
359- ));
389+ $proxy = new Clue\React\HttpProxy\ProxyConnector(
390+ '127.0.0.1:8080',
391+ $connector,
392+ array(
393+ 'Proxy-Authorization' => 'Bearer abc123',
394+ 'User-Agent' => 'ReactPHP'
395+ )
396+ );
360397```
361398
362399#### Advanced secure proxy connections
@@ -373,8 +410,10 @@ If you want to connect to a (rather rare) HTTPS proxy, you may want use the
373410instance to create a secure connection to the proxy:
374411
375412``` php
376- $connector = new Connector($loop);
377- $proxy = new ProxyConnector('https://127.0.0.1:443', $connector);
413+ $proxy = new Clue\React\HttpProxy\ProxyConnector(
414+ 'https://127.0.0.1:443',
415+ new React\Socket\Connector($loop)
416+ );
378417
379418$proxy->connect('tcp://smtp.googlemail.com:587');
380419```
@@ -391,9 +430,12 @@ having to rely on explicit [authentication](#authentication).
391430You can simply use the ` http+unix:// ` URI scheme like this:
392431
393432``` php
394- $proxy = new ProxyConnector('http+unix:///tmp/proxy.sock', $connector);
433+ $proxy = new Clue\React\HttpProxy\ProxyConnector(
434+ 'http+unix:///tmp/proxy.sock',
435+ new React\Socket\Connector($loop)
436+ );
395437
396- $proxy->connect('tcp://google.com:80')->then(function (ConnectionInterface $stream ) {
438+ $proxy->connect('tcp://google.com:80')->then(function (React\Socket\ ConnectionInterface $connection ) {
397439 // connected…
398440});
399441```
@@ -402,7 +444,10 @@ Similarly, you can also combine this with [authentication](#authentication)
402444like this:
403445
404446``` php
405- $proxy = new ProxyConnector('http+unix://user:pass@/tmp/proxy.sock', $connector);
447+ $proxy = new Clue\React\HttpProxy\ProxyConnector(
448+ 'http+unix://user:pass@/tmp/proxy.sock',
449+ new React\Socket\Connector($loop)
450+ );
406451```
407452
408453> Note that Unix domain sockets (UDS) are considered advanced usage and PHP only
0 commit comments