-
-
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.
Merge pull request #25 from clue-labs/custom-headers
Add support for custom HTTP request headers
- Loading branch information
Showing
4 changed files
with
115 additions
and
6 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<?php | ||
|
||
// A simple example which requests https://google.com/ through an HTTP CONNECT proxy. | ||
// The proxy can be given as first argument and defaults to localhost:8080 otherwise. | ||
// | ||
// For illustration purposes only. If you want to send HTTP requests in a real | ||
// world project, take a look at https://github.com/clue/reactphp-buzz#http-proxy | ||
|
||
use Clue\React\HttpProxy\ProxyConnector; | ||
use React\Socket\Connector; | ||
use React\Socket\ConnectionInterface; | ||
|
||
require __DIR__ . '/../vendor/autoload.php'; | ||
|
||
$url = isset($argv[1]) ? $argv[1] : '127.0.0.1:8080'; | ||
|
||
$loop = React\EventLoop\Factory::create(); | ||
|
||
$proxy = new ProxyConnector($url, new Connector($loop), array( | ||
'X-Custom-Header-1' => 'Value-1', | ||
'X-Custom-Header-2' => 'Value-2', | ||
)); | ||
$connector = new Connector($loop, array( | ||
'tcp' => $proxy, | ||
'timeout' => 3.0, | ||
'dns' => false, | ||
)); | ||
|
||
$connector->connect('tls://google.com:443')->then(function (ConnectionInterface $stream) { | ||
$stream->write("GET / HTTP/1.1\r\nHost: google.com\r\nConnection: close\r\n\r\n"); | ||
$stream->on('data', function ($chunk) { | ||
echo $chunk; | ||
}); | ||
}, '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
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