Skip to content

Commit 0aaacb8

Browse files
authored
Merge pull request #87 from claudiosdc/Fix
Converts "wss" scheme into "https" scheme
2 parents addec34 + 00a49ef commit 0aaacb8

File tree

2 files changed

+42
-5
lines changed

2 files changed

+42
-5
lines changed

src/Connector.php

+1-5
Original file line numberDiff line numberDiff line change
@@ -119,11 +119,7 @@ protected function generateRequest($url, array $subProtocols, array $headers) {
119119
throw new \InvalidArgumentException(sprintf('Cannot connect to invalid URL (%s)', $url));
120120
}
121121

122-
$uri = $uri->withScheme('HTTP');
123-
124-
if (!$uri->getPort()) {
125-
$uri = $uri->withPort('wss' === $scheme ? 443 : 80);
126-
}
122+
$uri = $uri->withScheme('wss' === $scheme ? 'HTTPS' : 'HTTP');
127123

128124
$headers += ['User-Agent' => 'Ratchet-Pawl/0.3'];
129125

tests/unit/RequestUriTest.php

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?php
2+
/**
3+
* Created by claudio on 2018-12-31
4+
*/
5+
6+
use PHPUnit\Framework\TestCase;
7+
use React\EventLoop\Factory;
8+
use Ratchet\Client\Connector;
9+
use Psr\Http\Message\RequestInterface;
10+
11+
class RequestUriTest extends TestCase {
12+
protected static function getPrivateClassMethod($className, $methodName) {
13+
$class = new ReflectionClass($className);
14+
$method = $class->getMethod($methodName);
15+
$method->setAccessible(true);
16+
return $method;
17+
}
18+
19+
function uriDataProvider() {
20+
return [
21+
['ws://127.0.0.1/bla', 'http://127.0.0.1/bla'],
22+
['wss://127.0.0.1/bla', 'https://127.0.0.1/bla'],
23+
['ws://127.0.0.1:1234/bla', 'http://127.0.0.1:1234/bla'],
24+
['wss://127.0.0.1:4321/bla', 'https://127.0.0.1:4321/bla']
25+
];
26+
}
27+
28+
/**
29+
* @dataProvider uriDataProvider
30+
*/
31+
function testGeneratedRequestUri($uri, $expectedRequestUri) {
32+
$loop = Factory::create();
33+
34+
$connector = new Connector($loop);
35+
36+
$generateRequest = self::getPrivateClassMethod('\Ratchet\Client\Connector', 'generateRequest');
37+
$request = $generateRequest->invokeArgs($connector, [$uri, [], []]);
38+
39+
$this->assertEquals((string)$request->getUri(), $expectedRequestUri);
40+
}
41+
}

0 commit comments

Comments
 (0)