Skip to content

Commit 67de797

Browse files
authored
Merge pull request #169 from Textalk/v1.6-fixes
Fix issue with implicit default ports
2 parents 3f8fd6f + 26ee875 commit 67de797

6 files changed

+144
-1
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -64,4 +64,4 @@ Fredrik Liljegren, Armen Baghumian Sankbarani, Ruslan Bekenev,
6464
Joshua Thijssen, Simon Lipp, Quentin Bellus, Patrick McCarren, swmcdonnell,
6565
Ignas Bernotas, Mark Herhold, Andreas Palm, Sören Jensen, pmaasz, Alexey Stavrov,
6666
Michael Slezak, Pierre Seznec, rmeisler, Nickolay V. Shmyrev, Christoph Kempen,
67-
Marc Roberts, Antonio Mora, Simon Podlipsky.
67+
Marc Roberts, Antonio Mora, Simon Podlipsky, etrinh.

docs/Changelog.md

+4
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@
66

77
> PHP version `^7.4|^8.0`
88
9+
### `1.6.3`
10+
11+
* Fix issue with implicit default ports (@etrinh, @sirn-se)
12+
913
### `1.6.2`
1014

1115
* Fix issue where port was missing in socket uri (@sirn-se)

lib/Client.php

+1
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,7 @@ protected function connect(): void
307307

308308
$host_uri = $this->socket_uri
309309
->withScheme($this->socket_uri->getScheme() == 'wss' ? 'ssl' : 'tcp')
310+
->withPort($this->socket_uri->getPort() ?? ($this->socket_uri->getScheme() == 'wss' ? 443 : 80))
310311
->withPath('')
311312
->withQuery('')
312313
->withFragment('')

tests/ClientTest.php

+20
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,26 @@ public function testClientRelativePath(): void
8282
$this->assertTrue(MockSocket::isEmpty());
8383
}
8484

85+
public function testClientWsDefaultPort(): void
86+
{
87+
MockSocket::initialize('client.connect-default-port-ws', $this);
88+
$uri = new Uri('ws://localhost');
89+
$uri = $uri->withPath('my/mock/path');
90+
$client = new Client($uri);
91+
$client->send('Connect');
92+
$this->assertTrue(MockSocket::isEmpty());
93+
}
94+
95+
public function testClientWssDefaultPort(): void
96+
{
97+
MockSocket::initialize('client.connect-default-port-wss', $this);
98+
$uri = new Uri('wss://localhost');
99+
$uri = $uri->withPath('my/mock/path');
100+
$client = new Client($uri);
101+
$client->send('Connect');
102+
$this->assertTrue(MockSocket::isEmpty());
103+
}
104+
85105
public function testClientWithTimeout(): void
86106
{
87107
MockSocket::initialize('client.connect-timeout', $this);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
[
2+
{
3+
"function": "stream_context_create",
4+
"params": [],
5+
"return": "@mock-stream-context"
6+
},
7+
{
8+
"function": "stream_socket_client",
9+
"params": [
10+
"tcp:\/\/localhost:80",
11+
null,
12+
null,
13+
5,
14+
4,
15+
"@mock-stream-context"
16+
],
17+
"return": "@mock-stream"
18+
},
19+
{
20+
"function": "get_resource_type",
21+
"params": [
22+
"@mock-stream"
23+
],
24+
"return": "stream"
25+
},
26+
{
27+
"function": "stream_set_timeout",
28+
"params": [
29+
"@mock-stream",
30+
5
31+
],
32+
"return": true
33+
},
34+
{
35+
"function": "fwrite",
36+
"params": [
37+
"@mock-stream",
38+
"GET /my/mock/path HTTP/1.1\r\nHost: localhost:80\r\nUser-Agent: websocket-client-php\r\nConnection: Upgrade\r\nUpgrade: websocket\r\nSec-WebSocket-Key: {key}\r\nSec-WebSocket-Version: 13\r\n\r\n"
39+
],
40+
"input-op": "key-save",
41+
"return": 224
42+
},
43+
{
44+
"function": "fgets",
45+
"params": [
46+
"@mock-stream",
47+
1024
48+
],
49+
"return-op": "key-respond",
50+
"return": "HTTP\/1.1 101 Switching Protocols\r\nUpgrade: websocket\r\nConnection: Upgrade\r\nSec-WebSocket-Accept: {key}\r\n\r\n"
51+
},
52+
{
53+
"function": "fwrite",
54+
"params": [
55+
"@mock-stream"
56+
],
57+
"return": 13
58+
}
59+
]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
[
2+
{
3+
"function": "stream_context_create",
4+
"params": [],
5+
"return": "@mock-stream-context"
6+
},
7+
{
8+
"function": "stream_socket_client",
9+
"params": [
10+
"ssl:\/\/localhost:443",
11+
null,
12+
null,
13+
5,
14+
4,
15+
"@mock-stream-context"
16+
],
17+
"return": "@mock-stream"
18+
},
19+
{
20+
"function": "get_resource_type",
21+
"params": [
22+
"@mock-stream"
23+
],
24+
"return": "stream"
25+
},
26+
{
27+
"function": "stream_set_timeout",
28+
"params": [
29+
"@mock-stream",
30+
5
31+
],
32+
"return": true
33+
},
34+
{
35+
"function": "fwrite",
36+
"params": [
37+
"@mock-stream",
38+
"GET /my/mock/path HTTP/1.1\r\nHost: localhost:443\r\nUser-Agent: websocket-client-php\r\nConnection: Upgrade\r\nUpgrade: websocket\r\nSec-WebSocket-Key: {key}\r\nSec-WebSocket-Version: 13\r\n\r\n"
39+
],
40+
"input-op": "key-save",
41+
"return": 224
42+
},
43+
{
44+
"function": "fgets",
45+
"params": [
46+
"@mock-stream",
47+
1024
48+
],
49+
"return-op": "key-respond",
50+
"return": "HTTP\/1.1 101 Switching Protocols\r\nUpgrade: websocket\r\nConnection: Upgrade\r\nSec-WebSocket-Accept: {key}\r\n\r\n"
51+
},
52+
{
53+
"function": "fwrite",
54+
"params": [
55+
"@mock-stream"
56+
],
57+
"return": 13
58+
}
59+
]

0 commit comments

Comments
 (0)