Skip to content

Commit 2f50827

Browse files
committed
Ignore URI scheme when matching selective connectors
1 parent f35aefc commit 2f50827

File tree

3 files changed

+14
-2
lines changed

3 files changed

+14
-2
lines changed

README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,15 @@ $selective = new ConnectionManagerSelective(array(
195195
));
196196
```
197197

198+
Each entry in the list MUST be in the form `host` or `host:port`, where
199+
`host` may contain the `*` wildcard character and `port` may be given as
200+
either an exact port number or as a range in the form of `min-max`.
201+
Passing anything else will result in an `InvalidArgumentException`.
202+
203+
> Note that the host will be matched exactly as-is otherwise. This means that
204+
if you only block `youtube.com`, this has no effect on `www.youtube.com`.
205+
You may want to add a second rule for `*.youtube.com` in this case.
206+
198207
## Install
199208

200209
The recommended way to install this library is [through Composer](http://getcomposer.org).

src/Multiple/ConnectionManagerSelective.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public function __construct(array $managers)
6565

6666
public function connect($uri)
6767
{
68-
$parts = parse_url('tcp://' . $uri);
68+
$parts = parse_url((strpos($uri, '://') === false ? 'tcp://' : '') . $uri);
6969
if (!isset($parts) || !isset($parts['scheme'], $parts['host'], $parts['port'])) {
7070
return Promise\reject(new InvalidArgumentException('Invalid URI'));
7171
}

tests/Multiple/ConnectionManagerSelectiveTest.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ public function testNotMatchingDomainWillReject()
144144
$this->assertPromiseReject($promise);
145145
}
146146

147-
public function testReject()
147+
public function testRejectIfNotMatching()
148148
{
149149
$will = $this->createConnectionManagerMock(true);
150150

@@ -154,10 +154,13 @@ public function testReject()
154154
));
155155

156156
$this->assertPromiseResolve($cm->connect('www.google.com:443'));
157+
$this->assertPromiseResolve($cm->connect('tls://www.google.com:443'));
157158

158159
$this->assertPromiseReject($cm->connect('www.google.com:80'));
160+
$this->assertPromiseReject($cm->connect('tcp://www.google.com:80'));
159161

160162
$this->assertPromiseResolve($cm->connect('www.youtube.com:80'));
163+
$this->assertPromiseResolve($cm->connect('tcp://www.youtube.com:80'));
161164
}
162165

163166
public function testFirstEntryWinsIfMultipleMatch()

0 commit comments

Comments
 (0)