@@ -71,10 +71,7 @@ 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- $proxy = new Clue\React\HttpProxy\ProxyConnector(
75- '127.0.0.1:8080',
76- new React\Socket\Connector()
77- );
74+ $proxy = new Clue\React\HttpProxy\ProxyConnector('127.0.0.1:8080');
7875
7976$connector = new React\Socket\Connector(null, array(
8077 'tcp' => $proxy,
@@ -103,22 +100,34 @@ any destination by using an intermediary HTTP CONNECT proxy.
103100[you] -> [proxy] -> [destination]
104101```
105102
106- Its constructor simply accepts an HTTP proxy URL and a connector used to connect
107- to the proxy server address:
103+ Its constructor simply accepts an HTTP proxy URL with the proxy server address:
108104
109105``` php
110- $proxy = new Clue\React\HttpProxy\ProxyConnector(
111- 'http://127.0.0.1:8080',
112- new React\Socket\Connector()
113- );
106+ $proxy = new Clue\React\HttpProxy\ProxyConnector('127.0.0.1:8080');
114107```
115108
116109The proxy URL may or may not contain a scheme and port definition. The default
117110port will be ` 80 ` for HTTP (or ` 443 ` for HTTPS), but many common HTTP proxy
118111servers use custom ports (often the alternative HTTP port ` 8080 ` ).
119- In its most simple form, the given connector will be a
120- [ ` \React\Socket\Connector ` ] ( https://github.com/reactphp/socket#connector ) if you
121- 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+ ```
122131
123132This is the main class in this package.
124133Because it implements ReactPHP's standard
@@ -137,7 +146,7 @@ higher-level component:
137146
138147``` diff
139148- $acme = new AcmeApi($connector);
140- + $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);
141150+ $acme = new AcmeApi($proxy);
142151```
143152
@@ -150,10 +159,7 @@ As documented above, you can simply invoke its `connect()` method to establish
150159a streaming plain TCP/IP connection and use any higher level protocol like so:
151160
152161``` php
153- $proxy = new Clue\React\HttpProxy\ProxyConnector(
154- '127.0.0.1:8080',
155- new React\Socket\Connector()
156- );
162+ $proxy = new Clue\React\HttpProxy\ProxyConnector('127.0.0.1:8080');
157163
158164$proxy->connect('tcp://smtp.googlemail.com:587')->then(function (React\Socket\ConnectionInterface $connection) {
159165 $connection->write("EHLO local\r\n");
@@ -167,10 +173,7 @@ You can either use the `ProxyConnector` directly or you may want to wrap this co
167173in ReactPHP's [ ` Connector ` ] ( https://github.com/reactphp/socket#connector ) :
168174
169175``` php
170- $proxy = new Clue\React\HttpProxy\ProxyConnector(
171- '127.0.0.1:8080',
172- new React\Socket\Connector()
173- );
176+ $proxy = new Clue\React\HttpProxy\ProxyConnector('127.0.0.1:8080');
174177
175178$connector = new React\Socket\Connector(null, array(
176179 'tcp' => $proxy,
@@ -193,14 +196,10 @@ Many (public) proxy servers do in fact limit this to HTTPS (443) only.
193196This class can also be used if you want to establish a secure TLS connection
194197(formerly known as SSL) between you and your destination, such as when using
195198secure HTTPS to your destination site. You can simply wrap this connector in
196- ReactPHP's [ ` Connector ` ] ( https://github.com/reactphp/socket#connector ) or the
197- low-level [ ` SecureConnector ` ] ( https://github.com/reactphp/socket#secureconnector ) :
199+ ReactPHP's [ ` Connector ` ] ( https://github.com/reactphp/socket#connector ) :
198200
199201``` php
200- $proxy = new Clue\React\HttpProxy\ProxyConnector(
201- '127.0.0.1:8080',
202- new React\Socket\Connector()
203- );
202+ $proxy = new Clue\React\HttpProxy\ProxyConnector('127.0.0.1:8080');
204203
205204$connector = new React\Socket\Connector(null, array(
206205 'tcp' => $proxy,
@@ -227,10 +226,7 @@ In order to send HTTP requests, you first have to add a dependency for
227226This allows you to send both plain HTTP and TLS-encrypted HTTPS requests like this:
228227
229228``` php
230- $proxy = new Clue\React\HttpProxy\ProxyConnector(
231- '127.0.0.1:8080',
232- new React\Socket\Connector()
233- );
229+ $proxy = new Clue\React\HttpProxy\ProxyConnector('127.0.0.1:8080');
234230
235231$connector = new React\Socket\Connector(null, array(
236232 'tcp' => $proxy,
@@ -260,17 +256,12 @@ Many use cases require more control over the timeout and likely values much
260256smaller, usually in the range of a few seconds only.
261257
262258You can use ReactPHP's [ ` Connector ` ] ( https://github.com/reactphp/socket#connector )
263- or the low-level
264- [ ` TimeoutConnector ` ] ( https://github.com/reactphp/socket#timeoutconnector )
265259to decorate any given ` ConnectorInterface ` instance.
266260It provides the same ` connect() ` method, but will automatically reject the
267261underlying connection attempt if it takes too long:
268262
269263``` php
270- $proxy = new Clue\React\HttpProxy\ProxyConnector(
271- '127.0.0.1:8080',
272- new React\Socket\Connector()
273- );
264+ $proxy = new Clue\React\HttpProxy\ProxyConnector('127.0.0.1:8080');
274265
275266$connector = new React\Socket\Connector(null, array(
276267 'tcp' => $proxy,
@@ -314,10 +305,7 @@ Given that remote DNS resolution is assumed to be the preferred mode, all
314305other examples explicitly disable DNS resolution like this:
315306
316307``` php
317- $proxy = new Clue\React\HttpProxy\ProxyConnector(
318- '127.0.0.1:8080',
319- new React\Socket\Connector()
320- );
308+ $proxy = new Clue\React\HttpProxy\ProxyConnector('127.0.0.1:8080');
321309
322310$connector = new React\Socket\Connector(null, array(
323311 'tcp' => $proxy,
@@ -328,10 +316,7 @@ $connector = new React\Socket\Connector(null, array(
328316If you want to explicitly use * local DNS resolution* , you can use the following code:
329317
330318``` php
331- $proxy = new Clue\React\HttpProxy\ProxyConnector(
332- '127.0.0.1:8080',
333- new React\Socket\Connector()
334- );
319+ $proxy = new Clue\React\HttpProxy\ProxyConnector('127.0.0.1:8080');
335320
336321// set up Connector which uses Google's public DNS (8.8.8.8)
337322$connector = new React\Socket\Connector(null, array(
@@ -349,10 +334,7 @@ If your HTTP proxy server requires authentication, you may pass the username and
349334password as part of the HTTP proxy URL like this:
350335
351336``` php
352- $proxy = new Clue\React\HttpProxy\ProxyConnector(
353- 'http://user:pass@127.0.0.1:8080',
354- new React\Socket\Connector()
355- );
337+ $proxy = new Clue\React\HttpProxy\ProxyConnector('user:pass@127.0.0.1:8080');
356338```
357339
358340Note that both the username and password must be percent-encoded if they contain
@@ -361,11 +343,9 @@ special characters:
361343``` php
362344$user = 'he:llo';
363345$pass = 'p@ss';
346+ $url = rawurlencode($user) . ':' . rawurlencode($pass) . '@127.0.0.1:8080';
364347
365- $proxy = new Clue\React\HttpProxy\ProxyConnector(
366- rawurlencode($user) . ':' . rawurlencode($pass) . '@127.0.0.1:8080',
367- $connector
368- );
348+ $proxy = new Clue\React\HttpProxy\ProxyConnector($url);
369349```
370350
371351> The authentication details will be used for basic authentication and will be
@@ -388,7 +368,7 @@ you may simply pass an assoc array of additional request headers like this:
388368``` php
389369$proxy = new Clue\React\HttpProxy\ProxyConnector(
390370 '127.0.0.1:8080',
391- $connector ,
371+ null ,
392372 array(
393373 'Proxy-Authorization' => 'Bearer abc123',
394374 'User-Agent' => 'ReactPHP'
@@ -404,16 +384,10 @@ setup, because you can still establish a TLS connection between you and the
404384destination host as above.
405385
406386If you want to connect to a (rather rare) HTTPS proxy, you may want use the
407- ` https:// ` scheme (HTTPS default port 443) and use ReactPHP's
408- [ ` Connector ` ] ( https://github.com/reactphp/socket#connector ) or the low-level
409- [ ` SecureConnector ` ] ( https://github.com/reactphp/socket#secureconnector )
410- instance to create a secure connection to the proxy:
387+ ` https:// ` scheme (HTTPS default port 443) to create a secure connection to the proxy:
411388
412389``` php
413- $proxy = new Clue\React\HttpProxy\ProxyConnector(
414- 'https://127.0.0.1:443',
415- new React\Socket\Connector()
416- );
390+ $proxy = new Clue\React\HttpProxy\ProxyConnector('https://127.0.0.1:443');
417391
418392$proxy->connect('tcp://smtp.googlemail.com:587');
419393```
@@ -430,10 +404,7 @@ having to rely on explicit [authentication](#authentication).
430404You can simply use the ` http+unix:// ` URI scheme like this:
431405
432406``` php
433- $proxy = new Clue\React\HttpProxy\ProxyConnector(
434- 'http+unix:///tmp/proxy.sock',
435- new React\Socket\Connector()
436- );
407+ $proxy = new Clue\React\HttpProxy\ProxyConnector('http+unix:///tmp/proxy.sock');
437408
438409$proxy->connect('tcp://google.com:80')->then(function (React\Socket\ConnectionInterface $connection) {
439410 // connected…
@@ -444,10 +415,7 @@ Similarly, you can also combine this with [authentication](#authentication)
444415like this:
445416
446417``` php
447- $proxy = new Clue\React\HttpProxy\ProxyConnector(
448- 'http+unix://user:pass@/tmp/proxy.sock',
449- new React\Socket\Connector()
450- );
418+ $proxy = new Clue\React\HttpProxy\ProxyConnector('http+unix://user:pass@/tmp/proxy.sock');
451419```
452420
453421> Note that Unix domain sockets (UDS) are considered advanced usage and PHP only
0 commit comments