Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,15 @@ $selective = new ConnectionManagerSelective(array(
));
```

Each entry in the list MUST be in the form `host` or `host:port`, where
`host` may contain the `*` wildcard character and `port` may be given as
either an exact port number or as a range in the form of `min-max`.
Passing anything else will result in an `InvalidArgumentException`.

> Note that the host will be matched exactly as-is otherwise. This means that
if you only block `youtube.com`, this has no effect on `www.youtube.com`.
You may want to add a second rule for `*.youtube.com` in this case.

## Install

The recommended way to install this library is [through Composer](http://getcomposer.org).
Expand Down
2 changes: 1 addition & 1 deletion src/Multiple/ConnectionManagerSelective.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public function __construct(array $managers)

public function connect($uri)
{
$parts = parse_url('tcp://' . $uri);
$parts = parse_url((strpos($uri, '://') === false ? 'tcp://' : '') . $uri);
if (!isset($parts) || !isset($parts['scheme'], $parts['host'], $parts['port'])) {
return Promise\reject(new InvalidArgumentException('Invalid URI'));
}
Expand Down
5 changes: 4 additions & 1 deletion tests/Multiple/ConnectionManagerSelectiveTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ public function testNotMatchingDomainWillReject()
$this->assertPromiseReject($promise);
}

public function testReject()
public function testRejectIfNotMatching()
{
$will = $this->createConnectionManagerMock(true);

Expand All @@ -154,10 +154,13 @@ public function testReject()
));

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

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

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

public function testFirstEntryWinsIfMultipleMatch()
Expand Down