Skip to content

Commit

Permalink
Clean up examples
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonFrings committed Sep 3, 2020
1 parent 903ac34 commit be89028
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 16 deletions.
12 changes: 8 additions & 4 deletions examples/01-http-request.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,20 @@
//
// $ php leproxy-latest.php
//
// To run the example, go to the project root and run:
// To run the example (The proxy deafults to localhost:8080), go to the project root and run:
//
// $ php examples/01-http-requests.php
//
// The proxy can be given as first argument and defaults to localhost:8080 otherwise.
use React\HTTP\Browser;
// If you want to run the same example with any other proxy URL, just use:
//
// $ http_proxy=127.0.0.1.8181 php examples/01-http-requests.php

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

$url = isset($argv[1]) ? $argv[1] : '127.0.0.1:8080';
$url = getenv('http_proxy');
if ($url === false) {
$url = '127.0.0.1:8080';
}

$loop = React\EventLoop\Factory::create();
$proxy = new Clue\React\HttpProxy\ProxyConnector($url, new React\Socket\Connector($loop));
Expand Down
9 changes: 7 additions & 2 deletions examples/11-proxy-raw-https-protocol.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@
//
// $ php examples/11-proxy-raw-https-protocol.php
//
// The proxy can be given as first argument and defaults to localhost:8080 otherwise.
// If you want to run the same example with any other proxy URL, just use:
//
// $ http_proxy=127.0.0.1.8181 php examples/11-proxy-raw-https-protocol.php
//
// For illustration purposes only. If you want to send HTTP requests in a real
// world project, take a look at example #01 and https://github.com/reactphp/http#client-usage.
Expand All @@ -20,7 +22,10 @@

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

$url = isset($argv[1]) ? $argv[1] : '127.0.0.1:8080';
$url = getenv('http_proxy');
if ($url === false) {
$url = '127.0.0.1:8080';
}

$loop = React\EventLoop\Factory::create();

Expand Down
11 changes: 7 additions & 4 deletions examples/12-optional-proxy-raw-https-protocol.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@
//
// $ php examples/12-optional-proxy-raw-https-protocol.php
//
// The Proxy can be given as first argument or does not use a proxy otherwise.
// To run the same example with your proxy, the proxy URL can be given as an environment variable:
//
// $ http_proxy=127.0.0.1.8181 php examples/12-optional-proxy-raw-https-protocol.php
//
// This example highlights how changing from direct connection to using a proxy
// actually adds very little complexity and does not mess with your actual
// network protocol otherwise.
Expand All @@ -24,9 +27,9 @@

$connector = new Connector($loop);

// first argument given? use this as the proxy URL
if (isset($argv[1])) {
$proxy = new ProxyConnector($argv[1], $connector);
$url = getenv('http_proxy');
if ($url !== false) {
$proxy = new ProxyConnector($url, $connector);
$connector = new Connector($loop, array(
'tcp' => $proxy,
'timeout' => 3.0,
Expand Down
9 changes: 7 additions & 2 deletions examples/13-custom-proxy-headers.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@
//
// $ php examples/13-custom-proxy-headers.php
//
// The proxy can be given as first argument and defaults to localhost:8080 otherwise.
// If you want to run the same example with any other proxy URL, just use:
//
// $ http_proxy=127.0.0.1.8181 php examples/13-custom-proxy-headers.php
//
// For illustration purposes only. If you want to send HTTP requests in a real
// world project, take a look at example #01 and https://github.com/reactphp/http#client-usage.
Expand All @@ -20,7 +22,10 @@

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

$url = isset($argv[1]) ? $argv[1] : '127.0.0.1:8080';
$url = getenv('http_proxy');
if ($url === false) {
$url = '127.0.0.1:8080';
}

$loop = React\EventLoop\Factory::create();

Expand Down
10 changes: 8 additions & 2 deletions examples/21-proxy-raw-smtp-protocol.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@
//
// $ php examples/21-proxy-raw-smtp-protocol.php
//
// The proxy can be given as first argument and defaults to localhost:8080 otherwise.
// If you want to run the same example with any other proxy URL, just use:
//
// $ http_proxy=127.0.0.1.8181 php examples/21-proxy-raw-smtp-protocol.php
//
// Please note that MANY public proxies do not allow SMTP connections, YMMV.

use Clue\React\HttpProxy\ProxyConnector;
Expand All @@ -18,7 +21,10 @@

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

$url = isset($argv[1]) ? $argv[1] : '127.0.0.1:8080';
$url = getenv('http_proxy');
if ($url === false) {
$url = '127.0.0.1:8080';
}

$loop = React\EventLoop\Factory::create();

Expand Down
10 changes: 8 additions & 2 deletions examples/22-proxy-raw-smtps-protocol.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@
//
// $ php examples/22-proxy-raw-smtps-protocol.php
//
// The proxy can be given as first argument and defaults to localhost:8080 otherwise.
// If you want to run the same example with any other proxy URL, just use:
//
// $ http_proxy=127.0.0.1.8181 php examples/22-proxy-raw-smtps-protocol.php
//
// This example highlights how changing from plain connections (see previous
// example) to using a secure connection actually adds very little complexity
// and does not mess with your actual network protocol otherwise.
Expand All @@ -21,7 +24,10 @@

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

$url = isset($argv[1]) ? $argv[1] : '127.0.0.1:8080';
$url = getenv('http_proxy');
if ($url === false) {
$url = '127.0.0.1:8080';
}

$loop = React\EventLoop\Factory::create();

Expand Down

0 comments on commit be89028

Please sign in to comment.