Skip to content

Commit dfa551b

Browse files
committed
1. TcpConnection add properties websocketOrigin & websocketClientProtocol
2. Protocols/Ws::onConnect init websocketOrigin & websocketClientProtocol 3. Protocols/Websocket::input init websocketOrigin & websocketClientProtocol
1 parent 2bba509 commit dfa551b

File tree

3 files changed

+8
-2
lines changed

3 files changed

+8
-2
lines changed

src/Connection/TcpConnection.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@
6161
/**
6262
* TcpConnection.
6363
* @property string $websocketType
64+
* @property string|null websocketClientProtocol
65+
* @property string|null websocketOrigin
6466
*/
6567
class TcpConnection extends ConnectionInterface implements JsonSerializable
6668
{

src/Protocols/Websocket.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,8 @@ class Websocket
8484
*/
8585
public static function input(string $buffer, TcpConnection $connection): int
8686
{
87+
$connection->websocketOrigin = $connection->websocketOrigin ?? null;
88+
$connection->websocketClientProtocol = $connection->websocketClientProtocol ?? null;
8789
// Receive length.
8890
$recvLen = strlen($buffer);
8991
// We need more data.

src/Protocols/Ws.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,8 @@ public static function decode(string $bytes, AsyncTcpConnection $connection): st
323323
*/
324324
public static function onConnect(AsyncTcpConnection $connection): void
325325
{
326+
$connection->websocketOrigin = $connection->websocketOrigin ?? null;
327+
$connection->websocketClientProtocol = $connection->websocketClientProtocol ?? null;
326328
static::sendHandshake($connection);
327329
}
328330

@@ -372,8 +374,8 @@ public static function sendHandshake(AsyncTcpConnection $connection): void
372374
(!preg_match("/\nHost:/i", $userHeaderStr) ? "Host: $host\r\n" : '') .
373375
"Connection: Upgrade\r\n" .
374376
"Upgrade: websocket\r\n" .
375-
(isset($connection->websocketOrigin) ? "Origin: " . $connection->websocketOrigin . "\r\n" : '') .
376-
(isset($connection->websocketClientProtocol) ? "Sec-WebSocket-Protocol: " . $connection->websocketClientProtocol . "\r\n" : '') .
377+
($connection?->websocketOrigin ? "Origin: " . $connection->websocketOrigin . "\r\n" : '') .
378+
($connection?->websocketClientProtocol ? "Sec-WebSocket-Protocol: " . $connection->websocketClientProtocol . "\r\n" : '') .
377379
"Sec-WebSocket-Version: 13\r\n" .
378380
"Sec-WebSocket-Key: " . $connection->context->websocketSecKey . $userHeaderStr . "\r\n\r\n";
379381
$connection->send($header, true);

0 commit comments

Comments
 (0)