Skip to content

Commit 0707f62

Browse files
committed
Documentation and example for HTTP CONNECT proxy
1 parent 0b316c9 commit 0707f62

5 files changed

Lines changed: 56 additions & 9 deletions

File tree

README.md

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ mess with most of the low-level details.
5050
* [UriInterface](#uriinterface)
5151
* [ResponseException](#responseexception)
5252
* [Advanced](#advanced)
53+
* [HTTP proxy](#http-proxy)
5354
* [SOCKS proxy](#socks-proxy)
5455
* [Unix domain sockets](#unix-domain-sockets)
5556
* [Install](#install)
@@ -590,15 +591,32 @@ access its underlying [`ResponseInterface`](#responseinterface) object.
590591

591592
## Advanced
592593

594+
### HTTP proxy
595+
596+
You can also establish your outgoing connections through an HTTP CONNECT proxy server
597+
by adding a dependency to [clue/reactphp-http-proxy](https://github.com/clue/reactphp-http-proxy).
598+
599+
HTTP CONNECT proxy servers (also commonly known as "HTTPS proxy" or "SSL proxy")
600+
are commonly used to tunnel HTTPS traffic through an intermediary ("proxy"), to
601+
conceal the origin address (anonymity) or to circumvent address blocking
602+
(geoblocking). While many (public) HTTP CONNECT proxy servers often limit this
603+
to HTTPS port`443` only, this can technically be used to tunnel any TCP/IP-based
604+
protocol, such as plain HTTP and TLS-encrypted HTTPS.
605+
606+
See also the [HTTP CONNECT proxy example](examples/11-http-proxy.php).
607+
593608
### SOCKS proxy
594609

595610
You can also establish your outgoing connections through a SOCKS proxy server
596611
by adding a dependency to [clue/reactphp-socks](https://github.com/clue/reactphp-socks).
597612

598-
The SOCKS protocol operates at the TCP/IP layer and thus requires minimal effort at the HTTP application layer.
599-
This works for both plain HTTP and SSL encrypted HTTPS requests.
613+
The SOCKS proxy protocol family (SOCKS5, SOCKS4 and SOCKS4a) is commonly used to
614+
tunnel HTTP(S) traffic through an intermediary ("proxy"), to conceal the origin
615+
address (anonymity) or to circumvent address blocking (geoblocking). While many
616+
(public) SOCKS proxy servers often limit this to HTTP(S) port `80` and `443`
617+
only, this can technically be used to tunnel any TCP/IP-based protocol.
600618

601-
See also the [SOCKS example](examples/11-socks-proxy.php).
619+
See also the [SOCKS proxy example](examples/12-socks-proxy.php).
602620

603621
### Unix domain sockets
604622

@@ -623,7 +641,7 @@ $client->get('http://localhost/info')->then(function (ResponseInterface $respons
623641
});
624642
```
625643

626-
See also the [Unix Domain Sockets (UDS) example](examples/12-unix-domain-sockets.php).
644+
See also the [Unix Domain Sockets (UDS) example](examples/13-unix-domain-sockets.php).
627645

628646
## Install
629647

composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
},
2828
"require-dev": {
2929
"clue/block-react": "^1.0",
30+
"clue/http-proxy-react": "^1.3",
3031
"clue/socks-react": "^0.8",
3132
"phpunit/phpunit": "^7.0 || ^6.4 || ^5.7 || ^4.8.35",
3233
"react/http": "^0.8"

examples/11-http-proxy.php

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php
2+
3+
use Clue\React\Buzz\Browser;
4+
use Clue\React\HttpProxy\ProxyConnector as HttpConnectClient;
5+
use Psr\Http\Message\ResponseInterface;
6+
use React\EventLoop\Factory as LoopFactory;
7+
use React\Socket\Connector;
8+
9+
require __DIR__ . '/../vendor/autoload.php';
10+
11+
$loop = LoopFactory::create();
12+
13+
// create a new HTTP CONNECT proxy client which connects to a HTTP CONNECT proxy server listening on localhost:8080
14+
// not already running a HTTP CONNECT proxy server? Try LeProxy.org!
15+
$proxy = new HttpConnectClient('127.0.0.1:8080', new Connector($loop));
16+
17+
// create a Browser object that uses the HTTP CONNECT proxy client for connections
18+
$connector = new Connector($loop, array(
19+
'tcp' => $proxy,
20+
'dns' => false
21+
));
22+
$browser = new Browser($loop, $connector);
23+
24+
// demo fetching HTTP headers (or bail out otherwise)
25+
$browser->get('https://www.google.com/')->then(function (ResponseInterface $response) {
26+
echo RingCentral\Psr7\str($response);
27+
}, 'printf');
28+
29+
$loop->run();
Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,16 @@
55
use Psr\Http\Message\ResponseInterface;
66
use React\EventLoop\Factory as LoopFactory;
77
use React\Socket\Connector;
8-
use RingCentral\Psr7;
98

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

1211
$loop = LoopFactory::create();
1312

14-
// create a new SOCKS client which connects to a SOCKS server listening on localhost:1080
15-
// not already running a SOCKS server? Try this: ssh -D 1080 localhost
13+
// create a new SOCKS proxy client which connects to a SOCKS proxy server listening on localhost:1080
14+
// not already running a SOCKS proxy server? Try LeProxy.org or this: `ssh -D 1080 localhost`
1615
$proxy = new SocksClient('127.0.0.1:1080', new Connector($loop));
1716

18-
// create a Browser object that uses the SOCKS client for connections
17+
// create a Browser object that uses the SOCKS proxy client for connections
1918
$connector = new Connector($loop, array(
2019
'tcp' => $proxy,
2120
'dns' => false
@@ -24,7 +23,7 @@
2423

2524
// demo fetching HTTP headers (or bail out otherwise)
2625
$browser->get('https://www.google.com/')->then(function (ResponseInterface $response) {
27-
echo Psr7\str($response);
26+
echo RingCentral\Psr7\str($response);
2827
}, 'printf');
2928

3029
$loop->run();

0 commit comments

Comments
 (0)