Skip to content

Commit f917b07

Browse files
committed
Minor documentation improvements
1 parent 59f6309 commit f917b07

9 files changed

+42
-39
lines changed

README.md

+19-15
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
[![installs on Packagist](https://img.shields.io/packagist/dt/clue/http-proxy-react?color=blue&label=installs%20on%20Packagist)](https://packagist.org/packages/clue/http-proxy-react)
55

66
Async HTTP proxy connector, tunnel any TCP/IP-based protocol through an HTTP
7-
CONNECT proxy server, built on top of [ReactPHP](https://reactphp.org).
7+
CONNECT proxy server, built on top of [ReactPHP](https://reactphp.org/).
88

99
HTTP CONNECT proxy servers (also commonly known as "HTTPS proxy" or "SSL proxy")
1010
are commonly used to tunnel HTTPS traffic through an intermediary ("proxy"), to
@@ -71,20 +71,24 @@ The following example code demonstrates how this library can be used to send a
7171
secure HTTPS request to google.com through a local HTTP proxy server:
7272

7373
```php
74+
<?php
75+
76+
require __DIR__ . '/vendor/autoload.php';
77+
7478
$proxy = new Clue\React\HttpProxy\ProxyConnector('127.0.0.1:8080');
7579

7680
$connector = new React\Socket\Connector(array(
7781
'tcp' => $proxy,
78-
'timeout' => 3.0,
7982
'dns' => false
8083
));
8184

82-
$connector->connect('tls://google.com:443')->then(function (React\Socket\ConnectionInterface $connection) {
83-
$connection->write("GET / HTTP/1.1\r\nHost: google.com\r\nConnection: close\r\n\r\n");
84-
$connection->on('data', function ($chunk) {
85-
echo $chunk;
86-
});
87-
}, 'printf');
85+
$browser = new React\Http\Browser($connector);
86+
87+
$browser->get('https://google.com/')->then(function (Psr\Http\Message\ResponseInterface $response) {
88+
var_dump($response->getHeaders(), (string) $response->getBody());
89+
}, function (Exception $e) {
90+
echo 'Error: ' . $e->getMessage() . PHP_EOL;
91+
});
8892
```
8993

9094
See also the [examples](examples).
@@ -334,7 +338,7 @@ If your HTTP proxy server requires authentication, you may pass the username and
334338
password as part of the HTTP proxy URL like this:
335339

336340
```php
337-
$proxy = new Clue\React\HttpProxy\ProxyConnector('user:pass@127.0.0.1:8080');
341+
$proxy = new Clue\React\HttpProxy\ProxyConnector('alice:password@127.0.0.1:8080');
338342
```
339343

340344
Note that both the username and password must be percent-encoded if they contain
@@ -415,7 +419,7 @@ Similarly, you can also combine this with [authentication](#authentication)
415419
like this:
416420

417421
```php
418-
$proxy = new Clue\React\HttpProxy\ProxyConnector('http+unix://user:pass@/tmp/proxy.sock');
422+
$proxy = new Clue\React\HttpProxy\ProxyConnector('http+unix://alice:password@/tmp/proxy.sock');
419423
```
420424

421425
> Note that Unix domain sockets (UDS) are considered advanced usage and PHP only
@@ -430,7 +434,7 @@ $proxy = new Clue\React\HttpProxy\ProxyConnector('http+unix://user:pass@/tmp/pro
430434

431435
## Install
432436

433-
The recommended way to install this library is [through Composer](https://getcomposer.org).
437+
The recommended way to install this library is [through Composer](https://getcomposer.org/).
434438
[New to Composer?](https://getcomposer.org/doc/00-intro.md)
435439

436440
This project follows [SemVer](https://semver.org/).
@@ -445,12 +449,12 @@ See also the [CHANGELOG](CHANGELOG.md) for details about version upgrades.
445449
This project aims to run on any platform and thus does not require any PHP
446450
extensions and supports running on legacy PHP 5.3 through current PHP 8+ and
447451
HHVM.
448-
It's *highly recommended to use PHP 7+* for this project.
452+
It's *highly recommended to use the latest supported PHP version* for this project.
449453

450454
## Tests
451455

452456
To run the test suite, you first need to clone this repo and then install all
453-
dependencies [through Composer](https://getcomposer.org):
457+
dependencies [through Composer](https://getcomposer.org/):
454458

455459
```bash
456460
$ composer install
@@ -459,14 +463,14 @@ $ composer install
459463
To run the test suite, go to the project root and run:
460464

461465
```bash
462-
$ php vendor/bin/phpunit
466+
$ vendor/bin/phpunit
463467
```
464468

465469
The test suite contains tests that rely on a working internet connection,
466470
alternatively you can also run it like this:
467471

468472
```bash
469-
$ php vendor/bin/phpunit --exclude-group internet
473+
$ vendor/bin/phpunit --exclude-group internet
470474
```
471475

472476
## License

composer.json

+6-6
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,6 @@
1010
"email": "[email protected]"
1111
}
1212
],
13-
"autoload": {
14-
"psr-4": { "Clue\\React\\HttpProxy\\": "src/" }
15-
},
16-
"autoload-dev": {
17-
"psr-4": { "Clue\\Tests\\React\\HttpProxy\\": "tests/" }
18-
},
1913
"require": {
2014
"php": ">=5.3",
2115
"react/promise": " ^2.1 || ^1.2.1",
@@ -27,5 +21,11 @@
2721
"phpunit/phpunit": "^9.3 || ^5.7 || ^4.8",
2822
"react/event-loop": "^1.2",
2923
"react/http": "^1.5"
24+
},
25+
"autoload": {
26+
"psr-4": { "Clue\\React\\HttpProxy\\": "src/" }
27+
},
28+
"autoload-dev": {
29+
"psr-4": { "Clue\\Tests\\React\\HttpProxy\\": "tests/" }
3030
}
3131
}

examples/01-http-request.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,20 @@
55
//
66
// $ php leproxy.php
77
//
8-
// The proxy defaults to localhost:8080.
8+
// The proxy defaults to 127.0.0.1:8080.
99
// To run the example go to the project root and run:
1010
//
1111
// $ php examples/01-http-request.php
1212
//
1313
// To run the same example with your proxy, the proxy URL can be given as an environment variable:
1414
//
15-
// $ http_proxy=127.0.0.2:8080 php examples/01-http-request.php
15+
// $ http_proxy=127.0.0.1:8080 php examples/01-http-request.php
1616

1717
require __DIR__ . '/../vendor/autoload.php';
1818

1919
$url = getenv('http_proxy');
2020
if ($url === false) {
21-
$url = 'localhost:8080';
21+
$url = '127.0.0.1:8080';
2222
}
2323

2424
$proxy = new Clue\React\HttpProxy\ProxyConnector($url);

examples/02-optional-proxy-http-request.php

+1-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
//
1212
// To run the same example with your proxy, the proxy URL can be given as an environment variable:
1313
//
14-
// $ http_proxy=127.0.0.2:8080 php examples/02-optional-proxy-http-request.php
14+
// $ http_proxy=127.0.0.1:8080 php examples/02-optional-proxy-http-request.php
1515

1616
require __DIR__ . '/../vendor/autoload.php';
1717

@@ -22,7 +22,6 @@
2222

2323
$connector = new React\Socket\Connector(array(
2424
'tcp' => $proxy,
25-
'timeout' => 3.0,
2625
'dns' => false
2726
));
2827
}

examples/11-proxy-raw-https-protocol.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@
55
//
66
// $ php leproxy.php
77
//
8-
// The proxy defaults to localhost:8080.
8+
// The proxy defaults to 127.0.0.1:8080.
99
// To run the example, go to the project root and run:
1010
//
1111
// $ php examples/11-proxy-raw-https-protocol.php
1212
//
1313
// To run the same example with your proxy, the proxy URL can be given as an environment variable:
1414
//
15-
// $ http_proxy=127.0.0.2:8080 php examples/11-proxy-raw-https-protocol.php
15+
// $ http_proxy=127.0.0.1:8080 php examples/11-proxy-raw-https-protocol.php
1616
//
1717
// For illustration purposes only. If you want to send HTTP requests in a real
1818
// world project, take a look at example #01, example #02 and https://github.com/reactphp/http#client-usage.
@@ -21,7 +21,7 @@
2121

2222
$url = getenv('http_proxy');
2323
if ($url === false) {
24-
$url = 'localhost:8080';
24+
$url = '127.0.0.1:8080';
2525
}
2626

2727
$proxy = new Clue\React\HttpProxy\ProxyConnector($url);

examples/12-optional-proxy-raw-https-protocol.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
//
1212
// To run the same example with your proxy, the proxy URL can be given as an environment variable:
1313
//
14-
// $ http_proxy=127.0.0.2:8080 php examples/12-optional-proxy-raw-https-protocol.php
14+
// $ http_proxy=127.0.0.1:8080 php examples/12-optional-proxy-raw-https-protocol.php
1515
//
1616
// This example highlights how changing from direct connection to using a proxy
1717
// actually adds very little complexity and does not mess with your actual

examples/13-custom-proxy-headers.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@
55
//
66
// $ php leproxy.php
77
//
8-
// The proxy defaults to localhost:8080.
8+
// The proxy defaults to 127.0.0.1:8080.
99
// To run the example, go to the project root and run:
1010
//
1111
// $ php examples/13-custom-proxy-headers.php
1212
//
1313
// To run the same example with your proxy, the proxy URL can be given as an environment variable:
1414
//
15-
// $ http_proxy=127.0.0.2:8080 php examples/13-custom-proxy-headers.php
15+
// $ http_proxy=127.0.0.1:8080 php examples/13-custom-proxy-headers.php
1616
//
1717
// For illustration purposes only. If you want to send HTTP requests in a real
1818
// world project, take a look at example #01, example #02 and https://github.com/reactphp/http#client-usage.
@@ -21,7 +21,7 @@
2121

2222
$url = getenv('http_proxy');
2323
if ($url === false) {
24-
$url = 'localhost:8080';
24+
$url = '127.0.0.1:8080';
2525
}
2626

2727
$proxy = new Clue\React\HttpProxy\ProxyConnector(

examples/21-proxy-raw-smtp-protocol.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,22 @@
55
//
66
// $ php leproxy.php
77
//
8-
// The proxy defaults to localhost:8080.
8+
// The proxy defaults to 127.0.0.1:8080.
99
// To run the example, go to the project root and run:
1010
//
1111
// $ php examples/21-proxy-raw-smtp-protocol.php
1212
//
1313
// To run the same example with your proxy, the proxy URL can be given as an environment variable:
1414
//
15-
// $ http_proxy=127.0.0.2:8080 php examples/21-proxy-raw-smtp-protocol.php
15+
// $ http_proxy=127.0.0.1:8080 php examples/21-proxy-raw-smtp-protocol.php
1616
//
1717
// Please note that MANY public proxies do not allow SMTP connections, YMMV.
1818

1919
require __DIR__ . '/../vendor/autoload.php';
2020

2121
$url = getenv('http_proxy');
2222
if ($url === false) {
23-
$url = 'localhost:8080';
23+
$url = '127.0.0.1:8080';
2424
}
2525

2626
$proxy = new Clue\React\HttpProxy\ProxyConnector($url);

examples/22-proxy-raw-smtps-protocol.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@
55
//
66
// $ php leproxy.php
77
//
8-
// The proxy defaults to localhost:8080.
8+
// The proxy defaults to 127.0.0.1:8080.
99
// To run the example, go to the project root and run:
1010
//
1111
// $ php examples/22-proxy-raw-smtps-protocol.php
1212
//
1313
// To run the same example with your proxy, the proxy URL can be given as an environment variable:
1414
//
15-
// $ http_proxy=127.0.0.2:8080 php examples/22-proxy-raw-smtps-protocol.php
15+
// $ http_proxy=127.0.0.1:8080 php examples/22-proxy-raw-smtps-protocol.php
1616
//
1717
// This example highlights how changing from plain connections (see previous
1818
// example) to using a secure connection actually adds very little complexity
@@ -23,7 +23,7 @@
2323

2424
$url = getenv('http_proxy');
2525
if ($url === false) {
26-
$url = 'localhost:8080';
26+
$url = '127.0.0.1:8080';
2727
}
2828

2929
$proxy = new Clue\React\HttpProxy\ProxyConnector($url);

0 commit comments

Comments
 (0)