Skip to content

Commit

Permalink
Improve examples and README
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonFrings committed Oct 23, 2020
1 parent b5c1887 commit a42b3aa
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 13 deletions.
11 changes: 8 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,9 @@ $connector->connect('tls://smtp.googlemail.com:465')->then(function (ConnectionI

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

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:
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:

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

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

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

#### Connection timeout

Expand Down
10 changes: 6 additions & 4 deletions examples/01-http-request.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@
// The proxy defaults to localhost:8080.
// To run the example go to the project root and run:
//
// $ php examples/01-http-requests.php
// $ php examples/01-http-request.php
//
// To run the same example with your proxy, the proxy URL can be given as an environment variable:
//
// $ http_proxy=127.0.0.2:8080 php examples/01-http-requests.php
// $ http_proxy=127.0.0.2:8080 php examples/01-http-request.php

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

Expand All @@ -31,8 +31,10 @@

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

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

$loop->run();
4 changes: 3 additions & 1 deletion examples/02-optional-proxy-http-request.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@

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

$loop->run();
4 changes: 3 additions & 1 deletion examples/11-proxy-raw-https-protocol.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@
$stream->on('data', function ($chunk) {
echo $chunk;
});
}, 'printf');
}, function (Exception $error) {
echo 'Error: ' . $error->getMessage() . PHP_EOL;
});

$loop->run();
4 changes: 3 additions & 1 deletion examples/12-optional-proxy-raw-https-protocol.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@
$stream->on('data', function ($chunk) {
echo $chunk;
});
}, 'printf');
}, function (Exception $error) {
echo 'Error: ' . $error->getMessage() . PHP_EOL;
});

$loop->run();
4 changes: 3 additions & 1 deletion examples/13-custom-proxy-headers.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@
$stream->on('data', function ($chunk) {
echo $chunk;
});
}, 'printf');
}, function (Exception $error) {
echo 'Error: ' . $error->getMessage() . PHP_EOL;
});

$loop->run();
4 changes: 3 additions & 1 deletion examples/21-proxy-raw-smtp-protocol.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@
echo $chunk;
$stream->write("QUIT\r\n");
});
}, 'printf');
}, function (Exception $error) {
echo 'Error: ' . $error->getMessage() . PHP_EOL;
});

$loop->run();
4 changes: 3 additions & 1 deletion examples/22-proxy-raw-smtps-protocol.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@
echo $chunk;
$stream->write("QUIT\r\n");
});
}, 'printf');
}, function (Exception $error) {
echo 'Error: ' . $error->getMessage() . PHP_EOL;
});

$loop->run();

0 comments on commit a42b3aa

Please sign in to comment.