diff --git a/README.md b/README.md index c990f5e..1497557 100644 --- a/README.md +++ b/README.md @@ -203,12 +203,29 @@ $connector->connect('tls://smtp.googlemail.com:465')->then(function (ConnectionI #### HTTP requests -HTTP operates on a higher layer than this low-level HTTP CONNECT implementation. -If you want to issue HTTP requests, you can add a dependency for -[clue/reactphp-buzz](https://github.com/clue/reactphp-buzz). -It can interact with this library by issuing all -[HTTP requests through a HTTP CONNECT proxy server](https://github.com/clue/reactphp-buzz#http-proxy). -This works for both plain HTTP and TLS-encrypted HTTPS requests. +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: + +```php +$proxy = new Clue\React\HttpProxy\ProxyConnector( + 'http://127.0.0.1:8080', + 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()); +}); +``` + +See also [ReactPHP's HTTP client](https://github.com/reactphp/http#client-usage) and any of the [examples](examples) for more details. #### Connection timeout diff --git a/composer.json b/composer.json index bfdf556..0a3ce33 100644 --- a/composer.json +++ b/composer.json @@ -25,6 +25,7 @@ "require-dev": { "phpunit/phpunit": "^9.0 || ^7.0 || ^5.0 || ^4.8", "react/event-loop": "^1.0 || ^0.5 || ^0.4 || ^0.3", + "react/http": "^1.0", "clue/block-react": "^1.1" } } diff --git a/examples/01-http-request.php b/examples/01-http-request.php new file mode 100644 index 0000000..66bd786 --- /dev/null +++ b/examples/01-http-request.php @@ -0,0 +1,38 @@ + $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(); diff --git a/examples/02-optional-proxy-http-request.php b/examples/02-optional-proxy-http-request.php new file mode 100644 index 0000000..170ea7a --- /dev/null +++ b/examples/02-optional-proxy-http-request.php @@ -0,0 +1,38 @@ + $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(); diff --git a/examples/01-proxy-https.php b/examples/11-proxy-raw-https-protocol.php similarity index 55% rename from examples/01-proxy-https.php rename to examples/11-proxy-raw-https-protocol.php index c91f31d..873b39b 100644 --- a/examples/01-proxy-https.php +++ b/examples/11-proxy-raw-https-protocol.php @@ -1,10 +1,21 @@ $proxy, 'timeout' => 3.0, diff --git a/examples/03-custom-proxy-headers.php b/examples/13-custom-proxy-headers.php similarity index 58% rename from examples/03-custom-proxy-headers.php rename to examples/13-custom-proxy-headers.php index 13f049b..09163af 100644 --- a/examples/03-custom-proxy-headers.php +++ b/examples/13-custom-proxy-headers.php @@ -1,10 +1,21 @@