@@ -71,10 +71,7 @@ The following example code demonstrates how this library can be used to send a
71
71
secure HTTPS request to google.com through a local HTTP proxy server:
72
72
73
73
``` 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');
78
75
79
76
$connector = new React\Socket\Connector(null, array(
80
77
'tcp' => $proxy,
@@ -103,22 +100,34 @@ any destination by using an intermediary HTTP CONNECT proxy.
103
100
[you] -> [proxy] -> [destination]
104
101
```
105
102
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:
108
104
109
105
``` 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');
114
107
```
115
108
116
109
The proxy URL may or may not contain a scheme and port definition. The default
117
110
port will be ` 80 ` for HTTP (or ` 443 ` for HTTPS), but many common HTTP proxy
118
111
servers 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
+ ```
122
131
123
132
This is the main class in this package.
124
133
Because it implements ReactPHP's standard
@@ -137,7 +146,7 @@ higher-level component:
137
146
138
147
``` diff
139
148
- $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);
141
150
+ $acme = new AcmeApi($proxy);
142
151
```
143
152
@@ -150,10 +159,7 @@ As documented above, you can simply invoke its `connect()` method to establish
150
159
a streaming plain TCP/IP connection and use any higher level protocol like so:
151
160
152
161
``` 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');
157
163
158
164
$proxy->connect('tcp://smtp.googlemail.com:587')->then(function (React\Socket\ConnectionInterface $connection) {
159
165
$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
167
173
in ReactPHP's [ ` Connector ` ] ( https://github.com/reactphp/socket#connector ) :
168
174
169
175
``` 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');
174
177
175
178
$connector = new React\Socket\Connector(null, array(
176
179
'tcp' => $proxy,
@@ -193,14 +196,10 @@ Many (public) proxy servers do in fact limit this to HTTPS (443) only.
193
196
This class can also be used if you want to establish a secure TLS connection
194
197
(formerly known as SSL) between you and your destination, such as when using
195
198
secure 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 ) :
198
200
199
201
``` 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');
204
203
205
204
$connector = new React\Socket\Connector(null, array(
206
205
'tcp' => $proxy,
@@ -227,10 +226,7 @@ In order to send HTTP requests, you first have to add a dependency for
227
226
This allows you to send both plain HTTP and TLS-encrypted HTTPS requests like this:
228
227
229
228
``` 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');
234
230
235
231
$connector = new React\Socket\Connector(null, array(
236
232
'tcp' => $proxy,
@@ -260,17 +256,12 @@ Many use cases require more control over the timeout and likely values much
260
256
smaller, usually in the range of a few seconds only.
261
257
262
258
You can use ReactPHP's [ ` Connector ` ] ( https://github.com/reactphp/socket#connector )
263
- or the low-level
264
- [ ` TimeoutConnector ` ] ( https://github.com/reactphp/socket#timeoutconnector )
265
259
to decorate any given ` ConnectorInterface ` instance.
266
260
It provides the same ` connect() ` method, but will automatically reject the
267
261
underlying connection attempt if it takes too long:
268
262
269
263
``` 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');
274
265
275
266
$connector = new React\Socket\Connector(null, array(
276
267
'tcp' => $proxy,
@@ -314,10 +305,7 @@ Given that remote DNS resolution is assumed to be the preferred mode, all
314
305
other examples explicitly disable DNS resolution like this:
315
306
316
307
``` 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');
321
309
322
310
$connector = new React\Socket\Connector(null, array(
323
311
'tcp' => $proxy,
@@ -328,10 +316,7 @@ $connector = new React\Socket\Connector(null, array(
328
316
If you want to explicitly use * local DNS resolution* , you can use the following code:
329
317
330
318
``` 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');
335
320
336
321
// set up Connector which uses Google's public DNS (8.8.8.8)
337
322
$connector = new React\Socket\Connector(null, array(
@@ -349,10 +334,7 @@ If your HTTP proxy server requires authentication, you may pass the username and
349
334
password as part of the HTTP proxy URL like this:
350
335
351
336
``` php
352
- $proxy = new Clue\React\HttpProxy\ProxyConnector(
353
- 'http://user:
[email protected] :8080',
354
- new React\Socket\Connector()
355
- );
337
+ $proxy = new Clue\React\HttpProxy\ProxyConnector('user:
[email protected] :8080');
356
338
```
357
339
358
340
Note that both the username and password must be percent-encoded if they contain
@@ -361,11 +343,9 @@ special characters:
361
343
``` php
362
344
$user = 'he:llo';
363
345
$pass = 'p@ss';
346
+ $url = rawurlencode($user) . ':' . rawurlencode($pass) . '@127.0.0.1:8080';
364
347
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);
369
349
```
370
350
371
351
> 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:
388
368
``` php
389
369
$proxy = new Clue\React\HttpProxy\ProxyConnector(
390
370
'127.0.0.1:8080',
391
- $connector ,
371
+ null ,
392
372
array(
393
373
'Proxy-Authorization' => 'Bearer abc123',
394
374
'User-Agent' => 'ReactPHP'
@@ -404,16 +384,10 @@ setup, because you can still establish a TLS connection between you and the
404
384
destination host as above.
405
385
406
386
If 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:
411
388
412
389
``` 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');
417
391
418
392
$proxy->connect('tcp://smtp.googlemail.com:587');
419
393
```
@@ -430,10 +404,7 @@ having to rely on explicit [authentication](#authentication).
430
404
You can simply use the ` http+unix:// ` URI scheme like this:
431
405
432
406
``` 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');
437
408
438
409
$proxy->connect('tcp://google.com:80')->then(function (React\Socket\ConnectionInterface $connection) {
439
410
// connected…
@@ -444,10 +415,7 @@ Similarly, you can also combine this with [authentication](#authentication)
444
415
like this:
445
416
446
417
``` 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');
451
419
```
452
420
453
421
> Note that Unix domain sockets (UDS) are considered advanced usage and PHP only
0 commit comments