Skip to content

Commit

Permalink
Test implicit and explicit text messages
Browse files Browse the repository at this point in the history
  • Loading branch information
thekid committed Jan 19, 2025
1 parent ee3a34b commit 9d2bd54
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/main/php/xp/web/srv/ForwardMessages.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public function message($conn, $message) {
foreach (new EventSource($response->incoming()) as $event => $data) {
$value= strtr($data, ['\r' => "\r", '\n' => "\n"]);
switch ($event) {
case null: case 'text': $conn->send($value); break;
case 'text': case null: $conn->send($value); break;
case 'bytes': $conn->send(new Bytes($value)); break;
case 'close': {
sscanf($value, "%d:%[^\r]", $code, $reason);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php namespace web\unittest\server;

use test\{Assert, Test};
use test\{Assert, Test, Values};
use util\Bytes;
use web\unittest\Channel;
use websocket\protocol\Connection;
Expand All @@ -19,8 +19,8 @@ public function can_create() {
new ForwardMessages(new Channel([]));
}

#[Test]
public function text() {
#[Test, Values(["d\r\ndata: Tested\n\r\n0\r\n\r\n", "19\r\nevent: text\ndata: Tested\n\r\n0\r\n\r\n"])]
public function text($payload) {
$request= $this->message(
'POST /ws HTTP/1.1',
'Sec-WebSocket-Version: 9',
Expand All @@ -35,7 +35,7 @@ public function text() {
'Content-Type: text/event-stream',
'Transfer-Encoding: chunked',
'',
"d\r\ndata: Tested\n\r\n0\r\n\r\n"
$payload
);

$backend= new Channel([$response]);
Expand Down

0 comments on commit 9d2bd54

Please sign in to comment.