Skip to content

Commit

Permalink
Add query string to path
Browse files Browse the repository at this point in the history
  • Loading branch information
thekid committed Oct 5, 2024
1 parent 10a54f4 commit 3e1f509
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/main/php/websocket/WebSocket.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public function __construct($endpoint, $origin= 'localhost') {
$this->socket= new Socket($url['host'], $url['port'] ?? 80);
}
$this->path= $url['path'] ?? '/';
isset($url['query']) && $this->path.= '?'.$url['query'];
}
$this->origin= $origin;
}
Expand Down
5 changes: 5 additions & 0 deletions src/test/php/websocket/unittest/WebSocketTest.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ public function path($url, $expected) {
Assert::equals($expected, (new WebSocket($url))->path());
}

#[Test, Values([['ws://example.com', '/'], ['ws://example.com/?test=1&l=de', '/?test=1&l=de']])]
public function query($url, $expected) {
Assert::equals($expected, (new WebSocket($url))->path());
}

#[Test]
public function default_origin() {
Assert::equals('localhost', (new WebSocket('ws://example.com'))->origin());
Expand Down

0 comments on commit 3e1f509

Please sign in to comment.