From 126810b2f165c863ff491314c093ef9aa7ee2f9d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20L=C3=BCck?= Date: Mon, 10 Apr 2017 16:56:22 +0200 Subject: [PATCH 1/2] Replace deprecated SocketClient with new Socket component --- README.md | 12 ++++++------ composer.json | 2 +- examples/01-proxy-https.php | 6 +++--- examples/02-optional-proxy-https.php | 8 ++++---- examples/11-proxy-smtp.php | 4 ++-- examples/12-proxy-smtps.php | 6 +++--- src/ProxyConnector.php | 4 ++-- tests/FunctionalTest.php | 6 +++--- tests/ProxyConnectorTest.php | 18 +++++++++--------- 9 files changed, 33 insertions(+), 33 deletions(-) diff --git a/README.md b/README.md index a474300..913d221 100644 --- a/README.md +++ b/README.md @@ -47,7 +47,7 @@ establishing streaming connections, such as a normal TCP/IP connection. In order to use this library, you should understand how this integrates with its ecosystem. This base interface is actually defined in React's -[SocketClient component](https://github.com/reactphp/socket-client) and used +[Socket component](https://github.com/reactphp/socket) and used throughout React's ecosystem. Most higher-level components (such as HTTP, database or other networking @@ -64,7 +64,7 @@ The interface only offers a single method: The `connect(string $uri): PromiseInterface` method can be used to establish a streaming connection. It returns a [Promise](https://github.com/reactphp/promise) which either -fulfills with a [ConnectionInterface](https://github.com/reactphp/socket-client#connectioninterface) or +fulfills with a [ConnectionInterface](https://github.com/reactphp/socket#connectioninterface) or rejects with an `Exception`: ```php @@ -99,7 +99,7 @@ The proxy URL may or may not contain a scheme and port definition. The default port will be `80` for HTTP (or `443` for HTTPS), but many common HTTP proxy servers use custom ports. In its most simple form, the given connector will be a -[`TcpConnector`](https://github.com/reactphp/socket-client#tcpconnector) if you +[`TcpConnector`](https://github.com/reactphp/socket#tcpconnector) if you want to connect to a given IP address as above. This is the main class in this package. @@ -134,7 +134,7 @@ Many (public) proxy servers do in fact limit this to HTTPS (443) only. If you want to establish a TLS connection (such as HTTPS) between you and your destination, you may want to wrap this connector in a -[`SecureConnector`](https://github.com/reactphp/socket-client#secureconnector) +[`SecureConnector`](https://github.com/reactphp/socket#secureconnector) instance: ```php @@ -156,7 +156,7 @@ destination host as above. If you want to connect to a (rather rare) HTTPS proxy, you may want use its HTTPS port (443) and use a -[`SecureConnector`](https://github.com/reactphp/socket-client#secureconnector) +[`SecureConnector`](https://github.com/reactphp/socket#secureconnector) instance to create a secure connection to the proxy: ```php @@ -206,7 +206,7 @@ MIT * If you want to learn more about how the [`ConnectorInterface`](#connectorinterface) and its usual implementations look like, refer to the documentation of the underlying - [react/socket-client](https://github.com/reactphp/socket-client) component. + [react/socket](https://github.com/reactphp/socket) component. * As an alternative to an HTTP CONNECT proxy, you may also want to look into using a SOCKS (SOCKS4/SOCKS5) proxy instead. You may want to use [clue/socks-react](https://github.com/clue/php-socks-react) diff --git a/composer.json b/composer.json index 8f06bb3..8be592a 100644 --- a/composer.json +++ b/composer.json @@ -18,7 +18,7 @@ }, "require": { "php": ">=5.3", - "react/socket-client": "^0.7 || ^0.6", + "react/socket": "^0.7", "react/event-loop": "^0.4 || ^0.3", "react/promise": " ^2.1 || ^1.2", "ringcentral/psr7": "^1.2" diff --git a/examples/01-proxy-https.php b/examples/01-proxy-https.php index 92d1aee..f5cc1ce 100644 --- a/examples/01-proxy-https.php +++ b/examples/01-proxy-https.php @@ -4,9 +4,9 @@ // The proxy can be given as first argument and defaults to localhost:8080 otherwise. use Clue\React\HttpProxy\ProxyConnector; -use React\SocketClient\TcpConnector; -use React\SocketClient\SecureConnector; -use React\SocketClient\ConnectionInterface; +use React\Socket\TcpConnector; +use React\Socket\SecureConnector; +use React\Socket\ConnectionInterface; require __DIR__ . '/../vendor/autoload.php'; diff --git a/examples/02-optional-proxy-https.php b/examples/02-optional-proxy-https.php index accee91..4e83d73 100644 --- a/examples/02-optional-proxy-https.php +++ b/examples/02-optional-proxy-https.php @@ -8,11 +8,11 @@ // network protocol otherwise. use Clue\React\HttpProxy\ProxyConnector; -use React\SocketClient\TcpConnector; -use React\SocketClient\SecureConnector; -use React\SocketClient\DnsConnector; +use React\Socket\TcpConnector; +use React\Socket\SecureConnector; +use React\Socket\DnsConnector; use React\Dns\Resolver\Factory; -use React\SocketClient\ConnectionInterface; +use React\Socket\ConnectionInterface; require __DIR__ . '/../vendor/autoload.php'; diff --git a/examples/11-proxy-smtp.php b/examples/11-proxy-smtp.php index c307b4c..703ca66 100644 --- a/examples/11-proxy-smtp.php +++ b/examples/11-proxy-smtp.php @@ -5,8 +5,8 @@ // Please note that MANY public proxies do not allow SMTP connections, YMMV. use Clue\React\HttpProxy\ProxyConnector; -use React\SocketClient\TcpConnector; -use React\SocketClient\ConnectionInterface; +use React\Socket\TcpConnector; +use React\Socket\ConnectionInterface; require __DIR__ . '/../vendor/autoload.php'; diff --git a/examples/12-proxy-smtps.php b/examples/12-proxy-smtps.php index 247c6c0..6719f75 100644 --- a/examples/12-proxy-smtps.php +++ b/examples/12-proxy-smtps.php @@ -8,9 +8,9 @@ // Please note that MANY public proxies do not allow SMTP connections, YMMV. use Clue\React\HttpProxy\ProxyConnector; -use React\SocketClient\TcpConnector; -use React\SocketClient\SecureConnector; -use React\SocketClient\ConnectionInterface; +use React\Socket\TcpConnector; +use React\Socket\SecureConnector; +use React\Socket\ConnectionInterface; require __DIR__ . '/../vendor/autoload.php'; diff --git a/src/ProxyConnector.php b/src/ProxyConnector.php index 44f53a8..ff1f6af 100644 --- a/src/ProxyConnector.php +++ b/src/ProxyConnector.php @@ -2,13 +2,13 @@ namespace Clue\React\HttpProxy; -use React\SocketClient\ConnectorInterface; +use React\Socket\ConnectorInterface; use Exception; use InvalidArgumentException; use RuntimeException; use RingCentral\Psr7; use React\Promise\Deferred; -use React\SocketClient\ConnectionInterface; +use React\Socket\ConnectionInterface; /** * A simple Connector that uses an HTTP CONNECT proxy to create plain TCP/IP connections to any destination diff --git a/tests/FunctionalTest.php b/tests/FunctionalTest.php index db3f1c5..65b0a88 100644 --- a/tests/FunctionalTest.php +++ b/tests/FunctionalTest.php @@ -4,10 +4,10 @@ use React\EventLoop\Factory; use Clue\React\HttpProxy\ProxyConnector; -use React\SocketClient\TcpConnector; -use React\SocketClient\DnsConnector; +use React\Socket\TcpConnector; +use React\Socket\DnsConnector; use Clue\React\Block; -use React\SocketClient\SecureConnector; +use React\Socket\SecureConnector; class FunctionalTest extends AbstractTestCase { diff --git a/tests/ProxyConnectorTest.php b/tests/ProxyConnectorTest.php index 4abd70e..a97e3f6 100644 --- a/tests/ProxyConnectorTest.php +++ b/tests/ProxyConnectorTest.php @@ -4,7 +4,7 @@ use Clue\React\HttpProxy\ProxyConnector; use React\Promise\Promise; -use React\SocketClient\ConnectionInterface; +use React\Socket\ConnectionInterface; class ProxyConnectorTest extends AbstractTestCase { @@ -12,7 +12,7 @@ class ProxyConnectorTest extends AbstractTestCase public function setUp() { - $this->connector = $this->getMockBuilder('React\SocketClient\ConnectorInterface')->getMock(); + $this->connector = $this->getMockBuilder('React\Socket\ConnectorInterface')->getMock(); } /** @@ -69,7 +69,7 @@ public function testCancelPromiseWillCancelPendingConnection() public function testWillWriteToOpenConnection() { - $stream = $this->getMockBuilder('React\SocketClient\StreamConnection')->disableOriginalConstructor()->setMethods(array('close', 'write'))->getMock(); + $stream = $this->getMockBuilder('React\Socket\Connection')->disableOriginalConstructor()->setMethods(array('close', 'write'))->getMock(); $stream->expects($this->once())->method('write'); $promise = \React\Promise\resolve($stream); @@ -82,7 +82,7 @@ public function testWillWriteToOpenConnection() public function testRejectsAndClosesIfStreamWritesNonHttp() { - $stream = $this->getMockBuilder('React\SocketClient\StreamConnection')->disableOriginalConstructor()->setMethods(array('close', 'write'))->getMock(); + $stream = $this->getMockBuilder('React\Socket\Connection')->disableOriginalConstructor()->setMethods(array('close', 'write'))->getMock(); $promise = \React\Promise\resolve($stream); $this->connector->expects($this->once())->method('connect')->willReturn($promise); @@ -99,7 +99,7 @@ public function testRejectsAndClosesIfStreamWritesNonHttp() public function testRejectsAndClosesIfStreamWritesTooMuchData() { - $stream = $this->getMockBuilder('React\SocketClient\StreamConnection')->disableOriginalConstructor()->setMethods(array('close', 'write'))->getMock(); + $stream = $this->getMockBuilder('React\Socket\Connection')->disableOriginalConstructor()->setMethods(array('close', 'write'))->getMock(); $promise = \React\Promise\resolve($stream); $this->connector->expects($this->once())->method('connect')->willReturn($promise); @@ -116,7 +116,7 @@ public function testRejectsAndClosesIfStreamWritesTooMuchData() public function testRejectsAndClosesIfStreamReturnsNonSuccess() { - $stream = $this->getMockBuilder('React\SocketClient\StreamConnection')->disableOriginalConstructor()->setMethods(array('close', 'write'))->getMock(); + $stream = $this->getMockBuilder('React\Socket\Connection')->disableOriginalConstructor()->setMethods(array('close', 'write'))->getMock(); $promise = \React\Promise\resolve($stream); $this->connector->expects($this->once())->method('connect')->willReturn($promise); @@ -133,7 +133,7 @@ public function testRejectsAndClosesIfStreamReturnsNonSuccess() public function testResolvesIfStreamReturnsSuccess() { - $stream = $this->getMockBuilder('React\SocketClient\StreamConnection')->disableOriginalConstructor()->setMethods(array('close', 'write'))->getMock(); + $stream = $this->getMockBuilder('React\Socket\Connection')->disableOriginalConstructor()->setMethods(array('close', 'write'))->getMock(); $promise = \React\Promise\resolve($stream); $this->connector->expects($this->once())->method('connect')->willReturn($promise); @@ -153,7 +153,7 @@ public function testResolvesIfStreamReturnsSuccess() public function testResolvesIfStreamReturnsSuccessAndEmitsExcessiveData() { - $stream = $this->getMockBuilder('React\SocketClient\StreamConnection')->disableOriginalConstructor()->setMethods(array('close', 'write'))->getMock(); + $stream = $this->getMockBuilder('React\Socket\Connection')->disableOriginalConstructor()->setMethods(array('close', 'write'))->getMock(); $promise = \React\Promise\resolve($stream); $this->connector->expects($this->once())->method('connect')->willReturn($promise); @@ -172,7 +172,7 @@ public function testResolvesIfStreamReturnsSuccessAndEmitsExcessiveData() public function testCancelPromiseWillCloseOpenConnectionAndReject() { - $stream = $this->getMockBuilder('React\SocketClient\StreamConnection')->disableOriginalConstructor()->setMethods(array('close', 'write'))->getMock(); + $stream = $this->getMockBuilder('React\Socket\Connection')->disableOriginalConstructor()->setMethods(array('close', 'write'))->getMock(); $stream->expects($this->once())->method('close'); $promise = \React\Promise\resolve($stream); From 027eb715c3e5e9a4097f541d210411c79a105223 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20L=C3=BCck?= Date: Mon, 10 Apr 2017 18:04:00 +0200 Subject: [PATCH 2/2] Require work-around for shutting down half-closed socket on HHVM --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 8be592a..ebede44 100644 --- a/composer.json +++ b/composer.json @@ -18,7 +18,7 @@ }, "require": { "php": ">=5.3", - "react/socket": "^0.7", + "react/socket": "^0.7.1", "react/event-loop": "^0.4 || ^0.3", "react/promise": " ^2.1 || ^1.2", "ringcentral/psr7": "^1.2"