Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve examples and README #37

Merged
merged 1 commit into from
Oct 23, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 $e) {
echo 'Error: ' . $e->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
8 changes: 5 additions & 3 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 @@ -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 $e) {
echo 'Error: ' . $e->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 $e) {
echo 'Error: ' . $e->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 $e) {
echo 'Error: ' . $e->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 $e) {
echo 'Error: ' . $e->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 $e) {
echo 'Error: ' . $e->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 $e) {
echo 'Error: ' . $e->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 $e) {
echo 'Error: ' . $e->getMessage() . PHP_EOL;
});

$loop->run();