@@ -71,13 +71,9 @@ The following example code demonstrates how this library can be used to send a
7171secure HTTPS request to google.com through a local HTTP proxy server:
7272
7373``` php
74- $loop = React\EventLoop\Factory::create( );
74+ $proxy = new Clue\ React\HttpProxy\ProxyConnector('127.0.0.1:8080' );
7575
76- $proxy = new Clue\React\HttpProxy\ProxyConnector(
77- '127.0.0.1:8080',
78- new React\Socket\Connector($loop)
79- );
80- $connector = new React\Socket\Connector($loop, array(
76+ $connector = new React\Socket\Connector(null, array(
8177 'tcp' => $proxy,
8278 'timeout' => 3.0,
8379 'dns' => false
@@ -89,8 +85,6 @@ $connector->connect('tls://google.com:443')->then(function (React\Socket\Connect
8985 echo $chunk;
9086 });
9187}, 'printf');
92-
93- $loop->run();
9488```
9589
9690See also the [ examples] ( examples ) .
@@ -106,20 +100,34 @@ any destination by using an intermediary HTTP CONNECT proxy.
106100[you] -> [proxy] -> [destination]
107101```
108102
109- Its constructor simply accepts an HTTP proxy URL and a connector used to connect
110- to the proxy server address:
103+ Its constructor simply accepts an HTTP proxy URL with the proxy server address:
111104
112105``` php
113- $connector = new React\Socket\Connector($loop);
114- $proxy = new Clue\React\HttpProxy\ProxyConnector('http://127.0.0.1:8080', $connector);
106+ $proxy = new Clue\React\HttpProxy\ProxyConnector('127.0.0.1:8080');
115107```
116108
117109The proxy URL may or may not contain a scheme and port definition. The default
118110port will be ` 80 ` for HTTP (or ` 443 ` for HTTPS), but many common HTTP proxy
119111servers use custom ports (often the alternative HTTP port ` 8080 ` ).
120- In its most simple form, the given connector will be a
121- [ ` \React\Socket\Connector ` ] ( https://github.com/reactphp/socket#connector ) if you
122- want to connect to a given IP address as above.
112+
113+ If you need custom connector settings (DNS resolution, TLS parameters, timeouts,
114+ proxy servers etc.), you can explicitly pass a custom instance of the
115+ [ ` ConnectorInterface ` ] ( https://github.com/reactphp/socket#connectorinterface ) :
116+
117+ ``` php
118+ $connector = new React\Socket\Connector(null, array(
119+ 'dns' => '127.0.0.1',
120+ 'tcp' => array(
121+ 'bindto' => '192.168.10.1:0'
122+ ),
123+ 'tls' => array(
124+ 'verify_peer' => false,
125+ 'verify_peer_name' => false
126+ )
127+ ));
128+
129+ $proxy = new Clue\React\HttpProxy\ProxyConnector('127.0.0.1:8080', $connector);
130+ ```
123131
124132This is the main class in this package.
125133Because it implements ReactPHP's standard
@@ -138,7 +146,7 @@ higher-level component:
138146
139147``` diff
140148- $acme = new AcmeApi($connector);
141- + $proxy = new Clue\React\HttpProxy\ProxyConnector('http:// 127.0.0.1:8080', $connector);
149+ + $proxy = new Clue\React\HttpProxy\ProxyConnector('127.0.0.1:8080', $connector);
142150+ $acme = new AcmeApi($proxy);
143151```
144152
@@ -151,10 +159,7 @@ As documented above, you can simply invoke its `connect()` method to establish
151159a streaming plain TCP/IP connection and use any higher level protocol like so:
152160
153161``` php
154- $proxy = new Clue\React\HttpProxy\ProxyConnector(
155- '127.0.0.1:8080',
156- new React\Socket\Connector($loop)
157- );
162+ $proxy = new Clue\React\HttpProxy\ProxyConnector('127.0.0.1:8080');
158163
159164$proxy->connect('tcp://smtp.googlemail.com:587')->then(function (React\Socket\ConnectionInterface $connection) {
160165 $connection->write("EHLO local\r\n");
@@ -168,12 +173,9 @@ You can either use the `ProxyConnector` directly or you may want to wrap this co
168173in ReactPHP's [ ` Connector ` ] ( https://github.com/reactphp/socket#connector ) :
169174
170175``` php
171- $proxy = new Clue\React\HttpProxy\ProxyConnector(
172- '127.0.0.1:8080',
173- new React\Socket\Connector($loop)
174- );
176+ $proxy = new Clue\React\HttpProxy\ProxyConnector('127.0.0.1:8080');
175177
176- $connector = new React\Socket\Connector($loop , array(
178+ $connector = new React\Socket\Connector(null , array(
177179 'tcp' => $proxy,
178180 'dns' => false
179181));
@@ -194,16 +196,12 @@ Many (public) proxy servers do in fact limit this to HTTPS (443) only.
194196This class can also be used if you want to establish a secure TLS connection
195197(formerly known as SSL) between you and your destination, such as when using
196198secure HTTPS to your destination site. You can simply wrap this connector in
197- ReactPHP's [ ` Connector ` ] ( https://github.com/reactphp/socket#connector ) or the
198- low-level [ ` SecureConnector ` ] ( https://github.com/reactphp/socket#secureconnector ) :
199+ ReactPHP's [ ` Connector ` ] ( https://github.com/reactphp/socket#connector ) :
199200
200201``` php
201- $proxy = new Clue\React\HttpProxy\ProxyConnector(
202- '127.0.0.1:8080',
203- new React\Socket\Connector($loop)
204- );
202+ $proxy = new Clue\React\HttpProxy\ProxyConnector('127.0.0.1:8080');
205203
206- $connector = new React\Socket\Connector($loop , array(
204+ $connector = new React\Socket\Connector(null , array(
207205 'tcp' => $proxy,
208206 'dns' => false
209207));
@@ -228,17 +226,14 @@ In order to send HTTP requests, you first have to add a dependency for
228226This allows you to send both plain HTTP and TLS-encrypted HTTPS requests like this:
229227
230228``` php
231- $proxy = new Clue\React\HttpProxy\ProxyConnector(
232- '127.0.0.1:8080',
233- new React\Socket\Connector($loop)
234- );
229+ $proxy = new Clue\React\HttpProxy\ProxyConnector('127.0.0.1:8080');
235230
236- $connector = new React\Socket\Connector($loop , array(
231+ $connector = new React\Socket\Connector(null , array(
237232 'tcp' => $proxy,
238233 'dns' => false
239234));
240235
241- $browser = new React\Http\Browser($loop , $connector);
236+ $browser = new React\Http\Browser(null , $connector);
242237
243238$browser->get('https://example.com/')->then(function (Psr\Http\Message\ResponseInterface $response) {
244239 var_dump($response->getHeaders(), (string) $response->getBody());
@@ -261,19 +256,14 @@ Many use cases require more control over the timeout and likely values much
261256smaller, usually in the range of a few seconds only.
262257
263258You can use ReactPHP's [ ` Connector ` ] ( https://github.com/reactphp/socket#connector )
264- or the low-level
265- [ ` TimeoutConnector ` ] ( https://github.com/reactphp/socket#timeoutconnector )
266259to decorate any given ` ConnectorInterface ` instance.
267260It provides the same ` connect() ` method, but will automatically reject the
268261underlying connection attempt if it takes too long:
269262
270263``` php
271- $proxy = new Clue\React\HttpProxy\ProxyConnector(
272- '127.0.0.1:8080',
273- new React\Socket\Connector($loop)
274- );
264+ $proxy = new Clue\React\HttpProxy\ProxyConnector('127.0.0.1:8080');
275265
276- $connector = new React\Socket\Connector($loop , array(
266+ $connector = new React\Socket\Connector(null , array(
277267 'tcp' => $proxy,
278268 'dns' => false,
279269 'timeout' => 3.0
@@ -315,12 +305,9 @@ Given that remote DNS resolution is assumed to be the preferred mode, all
315305other examples explicitly disable DNS resolution like this:
316306
317307``` php
318- $proxy = new Clue\React\HttpProxy\ProxyConnector(
319- '127.0.0.1:8080',
320- new React\Socket\Connector($loop)
321- );
308+ $proxy = new Clue\React\HttpProxy\ProxyConnector('127.0.0.1:8080');
322309
323- $connector = new React\Socket\Connector($loop , array(
310+ $connector = new React\Socket\Connector(null , array(
324311 'tcp' => $proxy,
325312 'dns' => false
326313));
@@ -329,13 +316,10 @@ $connector = new React\Socket\Connector($loop, array(
329316If you want to explicitly use * local DNS resolution* , you can use the following code:
330317
331318``` php
332- $proxy = new Clue\React\HttpProxy\ProxyConnector(
333- '127.0.0.1:8080',
334- new React\Socket\Connector($loop)
335- );
319+ $proxy = new Clue\React\HttpProxy\ProxyConnector('127.0.0.1:8080');
336320
337321// set up Connector which uses Google's public DNS (8.8.8.8)
338- $connector = new React\Socket\Connector($loop , array(
322+ $connector = new React\Socket\Connector(null , array(
339323 'tcp' => $proxy,
340324 'dns' => '8.8.8.8'
341325));
@@ -350,10 +334,7 @@ If your HTTP proxy server requires authentication, you may pass the username and
350334password as part of the HTTP proxy URL like this:
351335
352336``` php
353- $proxy = new Clue\React\HttpProxy\ProxyConnector(
354- 'http://user:pass@127.0.0.1:8080',
355- new React\Socket\Connector($loop)
356- );
337+ $proxy = new Clue\React\HttpProxy\ProxyConnector('user:pass@127.0.0.1:8080');
357338```
358339
359340Note that both the username and password must be percent-encoded if they contain
@@ -362,11 +343,9 @@ special characters:
362343``` php
363344$user = 'he:llo';
364345$pass = 'p@ss';
346+ $url = rawurlencode($user) . ':' . rawurlencode($pass) . '@127.0.0.1:8080';
365347
366- $proxy = new Clue\React\HttpProxy\ProxyConnector(
367- rawurlencode($user) . ':' . rawurlencode($pass) . '@127.0.0.1:8080',
368- $connector
369- );
348+ $proxy = new Clue\React\HttpProxy\ProxyConnector($url);
370349```
371350
372351> The authentication details will be used for basic authentication and will be
@@ -389,7 +368,7 @@ you may simply pass an assoc array of additional request headers like this:
389368``` php
390369$proxy = new Clue\React\HttpProxy\ProxyConnector(
391370 '127.0.0.1:8080',
392- $connector ,
371+ null ,
393372 array(
394373 'Proxy-Authorization' => 'Bearer abc123',
395374 'User-Agent' => 'ReactPHP'
@@ -405,16 +384,10 @@ setup, because you can still establish a TLS connection between you and the
405384destination host as above.
406385
407386If you want to connect to a (rather rare) HTTPS proxy, you may want use the
408- ` https:// ` scheme (HTTPS default port 443) and use ReactPHP's
409- [ ` Connector ` ] ( https://github.com/reactphp/socket#connector ) or the low-level
410- [ ` SecureConnector ` ] ( https://github.com/reactphp/socket#secureconnector )
411- instance to create a secure connection to the proxy:
387+ ` https:// ` scheme (HTTPS default port 443) to create a secure connection to the proxy:
412388
413389``` php
414- $proxy = new Clue\React\HttpProxy\ProxyConnector(
415- 'https://127.0.0.1:443',
416- new React\Socket\Connector($loop)
417- );
390+ $proxy = new Clue\React\HttpProxy\ProxyConnector('https://127.0.0.1:443');
418391
419392$proxy->connect('tcp://smtp.googlemail.com:587');
420393```
@@ -431,10 +404,7 @@ having to rely on explicit [authentication](#authentication).
431404You can simply use the ` http+unix:// ` URI scheme like this:
432405
433406``` php
434- $proxy = new Clue\React\HttpProxy\ProxyConnector(
435- 'http+unix:///tmp/proxy.sock',
436- new React\Socket\Connector($loop)
437- );
407+ $proxy = new Clue\React\HttpProxy\ProxyConnector('http+unix:///tmp/proxy.sock');
438408
439409$proxy->connect('tcp://google.com:80')->then(function (React\Socket\ConnectionInterface $connection) {
440410 // connected…
@@ -445,10 +415,7 @@ Similarly, you can also combine this with [authentication](#authentication)
445415like this:
446416
447417``` php
448- $proxy = new Clue\React\HttpProxy\ProxyConnector(
449- 'http+unix://user:pass@/tmp/proxy.sock',
450- new React\Socket\Connector($loop)
451- );
418+ $proxy = new Clue\React\HttpProxy\ProxyConnector('http+unix://user:pass@/tmp/proxy.sock');
452419```
453420
454421> Note that Unix domain sockets (UDS) are considered advanced usage and PHP only
0 commit comments