Skip to content

Commit

Permalink
Merge pull request #169 from Textalk/v1.6-fixes
Browse files Browse the repository at this point in the history
Fix issue with implicit default ports
  • Loading branch information
sirn-se authored Nov 7, 2022
2 parents 3f8fd6f + 26ee875 commit 67de797
Show file tree
Hide file tree
Showing 6 changed files with 144 additions and 1 deletion.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,4 @@ Fredrik Liljegren, Armen Baghumian Sankbarani, Ruslan Bekenev,
Joshua Thijssen, Simon Lipp, Quentin Bellus, Patrick McCarren, swmcdonnell,
Ignas Bernotas, Mark Herhold, Andreas Palm, Sören Jensen, pmaasz, Alexey Stavrov,
Michael Slezak, Pierre Seznec, rmeisler, Nickolay V. Shmyrev, Christoph Kempen,
Marc Roberts, Antonio Mora, Simon Podlipsky.
Marc Roberts, Antonio Mora, Simon Podlipsky, etrinh.
4 changes: 4 additions & 0 deletions docs/Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@

> PHP version `^7.4|^8.0`
### `1.6.3`

* Fix issue with implicit default ports (@etrinh, @sirn-se)

### `1.6.2`

* Fix issue where port was missing in socket uri (@sirn-se)
Expand Down
1 change: 1 addition & 0 deletions lib/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,7 @@ protected function connect(): void

$host_uri = $this->socket_uri
->withScheme($this->socket_uri->getScheme() == 'wss' ? 'ssl' : 'tcp')
->withPort($this->socket_uri->getPort() ?? ($this->socket_uri->getScheme() == 'wss' ? 443 : 80))
->withPath('')
->withQuery('')
->withFragment('')
Expand Down
20 changes: 20 additions & 0 deletions tests/ClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,26 @@ public function testClientRelativePath(): void
$this->assertTrue(MockSocket::isEmpty());
}

public function testClientWsDefaultPort(): void
{
MockSocket::initialize('client.connect-default-port-ws', $this);
$uri = new Uri('ws://localhost');
$uri = $uri->withPath('my/mock/path');
$client = new Client($uri);
$client->send('Connect');
$this->assertTrue(MockSocket::isEmpty());
}

public function testClientWssDefaultPort(): void
{
MockSocket::initialize('client.connect-default-port-wss', $this);
$uri = new Uri('wss://localhost');
$uri = $uri->withPath('my/mock/path');
$client = new Client($uri);
$client->send('Connect');
$this->assertTrue(MockSocket::isEmpty());
}

public function testClientWithTimeout(): void
{
MockSocket::initialize('client.connect-timeout', $this);
Expand Down
59 changes: 59 additions & 0 deletions tests/scripts/client.connect-default-port-ws.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
[
{
"function": "stream_context_create",
"params": [],
"return": "@mock-stream-context"
},
{
"function": "stream_socket_client",
"params": [
"tcp:\/\/localhost:80",
null,
null,
5,
4,
"@mock-stream-context"
],
"return": "@mock-stream"
},
{
"function": "get_resource_type",
"params": [
"@mock-stream"
],
"return": "stream"
},
{
"function": "stream_set_timeout",
"params": [
"@mock-stream",
5
],
"return": true
},
{
"function": "fwrite",
"params": [
"@mock-stream",
"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"
],
"input-op": "key-save",
"return": 224
},
{
"function": "fgets",
"params": [
"@mock-stream",
1024
],
"return-op": "key-respond",
"return": "HTTP\/1.1 101 Switching Protocols\r\nUpgrade: websocket\r\nConnection: Upgrade\r\nSec-WebSocket-Accept: {key}\r\n\r\n"
},
{
"function": "fwrite",
"params": [
"@mock-stream"
],
"return": 13
}
]
59 changes: 59 additions & 0 deletions tests/scripts/client.connect-default-port-wss.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
[
{
"function": "stream_context_create",
"params": [],
"return": "@mock-stream-context"
},
{
"function": "stream_socket_client",
"params": [
"ssl:\/\/localhost:443",
null,
null,
5,
4,
"@mock-stream-context"
],
"return": "@mock-stream"
},
{
"function": "get_resource_type",
"params": [
"@mock-stream"
],
"return": "stream"
},
{
"function": "stream_set_timeout",
"params": [
"@mock-stream",
5
],
"return": true
},
{
"function": "fwrite",
"params": [
"@mock-stream",
"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"
],
"input-op": "key-save",
"return": 224
},
{
"function": "fgets",
"params": [
"@mock-stream",
1024
],
"return-op": "key-respond",
"return": "HTTP\/1.1 101 Switching Protocols\r\nUpgrade: websocket\r\nConnection: Upgrade\r\nSec-WebSocket-Accept: {key}\r\n\r\n"
},
{
"function": "fwrite",
"params": [
"@mock-stream"
],
"return": 13
}
]

0 comments on commit 67de797

Please sign in to comment.