Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 0703dda

Browse files
committed
Clean up examples
1 parent 903ac34 commit 0703dda

7 files changed

+63
-22
lines changed

examples/01-http-request.php

+9-4
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,21 @@
55
//
66
// $ php leproxy-latest.php
77
//
8-
// To run the example, go to the project root and run:
8+
// The proxy defaults to localhost:8080.
9+
// To run the example go to the project root and run:
910
//
1011
// $ php examples/01-http-requests.php
1112
//
12-
// The proxy can be given as first argument and defaults to localhost:8080 otherwise.
13-
use React\HTTP\Browser;
13+
// If you want to run the same example with any other proxy URL, just use:
14+
//
15+
// $ http_proxy=127.0.0.1:8181 php examples/01-http-requests.php
1416

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

17-
$url = isset($argv[1]) ? $argv[1] : '127.0.0.1:8080';
19+
$url = getenv('http_proxy');
20+
if ($url === false) {
21+
$url = '127.0.0.1:8080';
22+
}
1823

1924
$loop = React\EventLoop\Factory::create();
2025
$proxy = new Clue\React\HttpProxy\ProxyConnector($url, new React\Socket\Connector($loop));

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

+5-1
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,13 @@
55
//
66
// $ php examples/02-optional-proxy-http-request.php
77
//
8+
// If you chose the optional route, you can use any kind of proxy, for example https://github.com/leproxy/leproxy and execute it like this:
9+
//
10+
// $ php leproxy-latest.php
11+
//
812
// To run the same example with your proxy, the proxy URL can be given as an environment variable:
913
//
10-
// $ http_proxy=127.0.0.1.8181 php examples/02-optional-proxy-http-request.php
14+
// $ http_proxy=127.0.0.1:8181 php examples/02-optional-proxy-http-request.php
1115

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

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

+9-3
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,28 @@
55
//
66
// $ php leproxy-latest.php
77
//
8+
// The proxy defaults to localhost:8080.
89
// To run the example, go to the project root and run:
910
//
1011
// $ php examples/11-proxy-raw-https-protocol.php
1112
//
12-
// The proxy can be given as first argument and defaults to localhost:8080 otherwise.
13+
// If you want to run the same example with any other proxy URL, just use:
14+
//
15+
// $ http_proxy=127.0.0.1:8181 php examples/11-proxy-raw-https-protocol.php
1316
//
1417
// For illustration purposes only. If you want to send HTTP requests in a real
15-
// world project, take a look at example #01 and https://github.com/reactphp/http#client-usage.
18+
// world project, take a look at example #01, example #02 and https://github.com/reactphp/http#client-usage.
1619

1720
use Clue\React\HttpProxy\ProxyConnector;
1821
use React\Socket\Connector;
1922
use React\Socket\ConnectionInterface;
2023

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

23-
$url = isset($argv[1]) ? $argv[1] : '127.0.0.1:8080';
26+
$url = getenv('http_proxy');
27+
if ($url === false) {
28+
$url = '127.0.0.1:8080';
29+
}
2430

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

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

+13-7
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,24 @@
11
<?php
22

3-
// A simple example which requests https://google.com/ either directly or through
4-
// an HTTP CONNECT proxy.
3+
// A simple example which requests https://google.com/ directly (optional: Through an HTTP CONNECT proxy.)
54
// To run the example, go to the project root and run:
65
//
76
// $ php examples/12-optional-proxy-raw-https-protocol.php
87
//
9-
// The Proxy can be given as first argument or does not use a proxy otherwise.
8+
// If you chose the optional route, you can use any kind of proxy, for example https://github.com/leproxy/leproxy and execute it like this:
9+
//
10+
// $ php leproxy-latest.php
11+
//
12+
// To run the same example with your proxy, the proxy URL can be given as an environment variable:
13+
//
14+
// $ http_proxy=127.0.0.1:8181 php examples/12-optional-proxy-raw-https-protocol.php
15+
//
1016
// This example highlights how changing from direct connection to using a proxy
1117
// actually adds very little complexity and does not mess with your actual
1218
// network protocol otherwise.
1319
//
1420
// For illustration purposes only. If you want to send HTTP requests in a real
15-
// world project, take a look at example #01 and https://github.com/reactphp/http#client-usage.
21+
// world project, take a look at example #01, example #02 and https://github.com/reactphp/http#client-usage.
1622

1723
use Clue\React\HttpProxy\ProxyConnector;
1824
use React\Socket\Connector;
@@ -24,9 +30,9 @@
2430

2531
$connector = new Connector($loop);
2632

27-
// first argument given? use this as the proxy URL
28-
if (isset($argv[1])) {
29-
$proxy = new ProxyConnector($argv[1], $connector);
33+
$url = getenv('http_proxy');
34+
if ($url !== false) {
35+
$proxy = new ProxyConnector($url, $connector);
3036
$connector = new Connector($loop, array(
3137
'tcp' => $proxy,
3238
'timeout' => 3.0,

examples/13-custom-proxy-headers.php

+9-3
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,28 @@
55
//
66
// $ php leproxy-latest.php
77
//
8+
// The proxy defaults to localhost:8080.
89
// To run the example, go to the project root and run:
910
//
1011
// $ php examples/13-custom-proxy-headers.php
1112
//
12-
// The proxy can be given as first argument and defaults to localhost:8080 otherwise.
13+
// If you want to run the same example with any other proxy URL, just use:
14+
//
15+
// $ http_proxy=127.0.0.1:8181 php examples/13-custom-proxy-headers.php
1316
//
1417
// For illustration purposes only. If you want to send HTTP requests in a real
15-
// world project, take a look at example #01 and https://github.com/reactphp/http#client-usage.
18+
// world project, take a look at example #01, example #02 and https://github.com/reactphp/http#client-usage.
1619

1720
use Clue\React\HttpProxy\ProxyConnector;
1821
use React\Socket\Connector;
1922
use React\Socket\ConnectionInterface;
2023

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

23-
$url = isset($argv[1]) ? $argv[1] : '127.0.0.1:8080';
26+
$url = getenv('http_proxy');
27+
if ($url === false) {
28+
$url = '127.0.0.1:8080';
29+
}
2430

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

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

+9-2
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,15 @@
55
//
66
// $ php leproxy-latest.php
77
//
8+
// The proxy defaults to localhost:8080.
89
// To run the example, go to the project root and run:
910
//
1011
// $ php examples/21-proxy-raw-smtp-protocol.php
1112
//
12-
// The proxy can be given as first argument and defaults to localhost:8080 otherwise.
13+
// If you want to run the same example with any other proxy URL, just use:
14+
//
15+
// $ http_proxy=127.0.0.1:8181 php examples/21-proxy-raw-smtp-protocol.php
16+
//
1317
// Please note that MANY public proxies do not allow SMTP connections, YMMV.
1418

1519
use Clue\React\HttpProxy\ProxyConnector;
@@ -18,7 +22,10 @@
1822

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

21-
$url = isset($argv[1]) ? $argv[1] : '127.0.0.1:8080';
25+
$url = getenv('http_proxy');
26+
if ($url === false) {
27+
$url = '127.0.0.1:8080';
28+
}
2229

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

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

+9-2
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,15 @@
55
//
66
// $ php leproxy-latest.php
77
//
8+
// The proxy defaults to localhost:8080.
89
// To run the example, go to the project root and run:
910
//
1011
// $ php examples/22-proxy-raw-smtps-protocol.php
1112
//
12-
// The proxy can be given as first argument and defaults to localhost:8080 otherwise.
13+
// If you want to run the same example with any other proxy URL, just use:
14+
//
15+
// $ http_proxy=127.0.0.1:8181 php examples/22-proxy-raw-smtps-protocol.php
16+
//
1317
// This example highlights how changing from plain connections (see previous
1418
// example) to using a secure connection actually adds very little complexity
1519
// and does not mess with your actual network protocol otherwise.
@@ -21,7 +25,10 @@
2125

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

24-
$url = isset($argv[1]) ? $argv[1] : '127.0.0.1:8080';
28+
$url = getenv('http_proxy');
29+
if ($url === false) {
30+
$url = '127.0.0.1:8080';
31+
}
2532

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

0 commit comments

Comments
 (0)