Skip to content

Commit a42b3aa

Browse files
committed
Improve examples and README
1 parent b5c1887 commit a42b3aa

8 files changed

+32
-13
lines changed

README.md

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,9 @@ $connector->connect('tls://smtp.googlemail.com:465')->then(function (ConnectionI
205205

206206
This library also allows you to send HTTP requests through an HTTP CONNECT proxy server.
207207

208-
In order to send HTTP requests, you first have to add a dependency for [ReactPHP's async HTTP client](https://github.com/reactphp/http#client-usage). This allows you to send both plain HTTP and TLS-encrypted HTTPS requests like this:
208+
In order to send HTTP requests, you first have to add a dependency for
209+
[ReactPHP's async HTTP client](https://github.com/reactphp/http#client-usage).
210+
This allows you to send both plain HTTP and TLS-encrypted HTTPS requests like this:
209211

210212
```php
211213
$proxy = new Clue\React\HttpProxy\ProxyConnector(
@@ -222,10 +224,13 @@ $browser = new React\Http\Browser($loop, $connector);
222224

223225
$browser->get('https://example.com/')->then(function (Psr\Http\Message\ResponseInterface $response) {
224226
var_dump($response->getHeaders(), (string) $response->getBody());
225-
});
227+
}, function (Exception $error) {
228+
echo 'Error: ' . $error->getMessage() . PHP_EOL;
229+
});
226230
```
227231

228-
See also [ReactPHP's HTTP client](https://github.com/reactphp/http#client-usage) and any of the [examples](examples) for more details.
232+
See also [ReactPHP's HTTP client](https://github.com/reactphp/http#client-usage)
233+
and any of the [examples](examples) for more details.
229234

230235
#### Connection timeout
231236

examples/01-http-request.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@
88
// The proxy defaults to localhost:8080.
99
// To run the example go to the project root and run:
1010
//
11-
// $ php examples/01-http-requests.php
11+
// $ 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-requests.php
15+
// $ http_proxy=127.0.0.2:8080 php examples/01-http-request.php
1616

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

@@ -31,8 +31,10 @@
3131

3232
$browser = new React\Http\Browser($loop, $connector);
3333

34-
$browser->get('https://example.com/')->then(function (Psr\Http\Message\ResponseInterface $response) {
34+
$browser->get('https://example.comm/')->then(function (Psr\Http\Message\ResponseInterface $response) {
3535
var_dump($response->getHeaders(), (string) $response->getBody());
36-
}, 'printf');
36+
}, function (Exception $error) {
37+
echo 'Error: ' . $error->getMessage() . PHP_EOL;
38+
});
3739

3840
$loop->run();

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@
3333

3434
$browser->get('https://example.com/')->then(function (Psr\Http\Message\ResponseInterface $response) {
3535
var_dump($response->getHeaders(), (string) $response->getBody());
36-
}, 'printf');
36+
}, function (Exception $error) {
37+
echo 'Error: ' . $error->getMessage() . PHP_EOL;
38+
});
3739

3840
$loop->run();

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@
4242
$stream->on('data', function ($chunk) {
4343
echo $chunk;
4444
});
45-
}, 'printf');
45+
}, function (Exception $error) {
46+
echo 'Error: ' . $error->getMessage() . PHP_EOL;
47+
});
4648

4749
$loop->run();

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@
4545
$stream->on('data', function ($chunk) {
4646
echo $chunk;
4747
});
48-
}, 'printf');
48+
}, function (Exception $error) {
49+
echo 'Error: ' . $error->getMessage() . PHP_EOL;
50+
});
4951

5052
$loop->run();

examples/13-custom-proxy-headers.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@
4545
$stream->on('data', function ($chunk) {
4646
echo $chunk;
4747
});
48-
}, 'printf');
48+
}, function (Exception $error) {
49+
echo 'Error: ' . $error->getMessage() . PHP_EOL;
50+
});
4951

5052
$loop->run();

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@
4242
echo $chunk;
4343
$stream->write("QUIT\r\n");
4444
});
45-
}, 'printf');
45+
}, function (Exception $error) {
46+
echo 'Error: ' . $error->getMessage() . PHP_EOL;
47+
});
4648

4749
$loop->run();

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@
4545
echo $chunk;
4646
$stream->write("QUIT\r\n");
4747
});
48-
}, 'printf');
48+
}, function (Exception $error) {
49+
echo 'Error: ' . $error->getMessage() . PHP_EOL;
50+
});
4951

5052
$loop->run();

0 commit comments

Comments
 (0)