-
-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f8fa56f
commit 903ac34
Showing
9 changed files
with
112 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<?php | ||
|
||
// A simple example which uses an HTTP client to request https://example.com/ through an HTTP CONNECT proxy. | ||
// You can use any kind of proxy, for example https://github.com/leproxy/leproxy and execute it like this: | ||
// | ||
// $ php leproxy-latest.php | ||
// | ||
// To run the example, 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; | ||
|
||
require __DIR__ . '/../vendor/autoload.php'; | ||
|
||
$url = isset($argv[1]) ? $argv[1] : '127.0.0.1:8080'; | ||
|
||
$loop = React\EventLoop\Factory::create(); | ||
$proxy = new Clue\React\HttpProxy\ProxyConnector($url, new React\Socket\Connector($loop)); | ||
|
||
$connector = new React\Socket\Connector($loop, array( | ||
'tcp' => $proxy, | ||
'dns' => false | ||
)); | ||
|
||
$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()); | ||
}, 'printf'); | ||
|
||
$loop->run(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<?php | ||
|
||
// A simple example which uses an HTTP client to request https://example.com/ (optional: Through an HTTP CONNECT proxy.) | ||
// To run the example, go to the project root and run: | ||
// | ||
// $ php examples/02-optional-proxy-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.1.8181 php examples/02-optional-proxy-http-request.php | ||
|
||
require __DIR__ . '/../vendor/autoload.php'; | ||
|
||
$loop = React\EventLoop\Factory::create(); | ||
|
||
$connector = null; | ||
$url = getenv('http_proxy'); | ||
if ($url !== false) { | ||
$connector = new React\Socket\Connector($loop); | ||
$proxy = new Clue\React\HttpProxy\ProxyConnector($url, $connector); | ||
$connector = new React\Socket\Connector($loop, array( | ||
'tcp' => $proxy, | ||
'timeout' => 3.0, | ||
'dns' => false | ||
)); | ||
} | ||
|
||
$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()); | ||
}, 'printf'); | ||
|
||
$loop->run(); |
10 changes: 9 additions & 1 deletion
10
examples/01-proxy-https.php → examples/11-proxy-raw-https-protocol.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 9 additions & 1 deletion
10
examples/03-custom-proxy-headers.php → examples/13-custom-proxy-headers.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 10 additions & 2 deletions
12
examples/11-proxy-smtp.php → examples/21-proxy-raw-smtp-protocol.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 10 additions & 2 deletions
12
examples/12-proxy-smtps.php → examples/22-proxy-raw-smtps-protocol.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters