-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
WebSockets client: Add test and fix issues. (#109)
* Adds a test that uses a publicly available echo endpoint. * Didn't correctly buffer data received in the same packet as the headers. * Wrongly sent two Host: headers.
- Loading branch information
Erik Corry
authored
Jul 26, 2023
1 parent
6a227f4
commit 1e9de1e
Showing
4 changed files
with
33 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// Copyright (C) 2023 Toitware ApS. | ||
// Use of this source code is governed by a Zero-Clause BSD license that can | ||
// be found in the tests/TESTS_LICENSE file. | ||
import certificate_roots | ||
import expect show * | ||
import http | ||
import net | ||
|
||
URI ::= "wss://echo.websocket.events/" | ||
// This header is required by the WebSocket endpoint. | ||
ORIGIN ::= { "Origin": "http://echo.websocket.events" } | ||
MSG1 ::= "Hello, from Toit!" | ||
MSG2 ::= #[0xff, 0x00, 103] | ||
|
||
main: | ||
network := net.open | ||
client := http.Client network --root_certificates=[certificate_roots.ISRG_ROOT_X1] | ||
web_socket := client.web_socket --uri=URI --headers=(http.Headers.from_map ORIGIN) | ||
greeting := web_socket.receive | ||
expect_equals "echo.websocket.events sponsored by Lob.com" greeting | ||
print greeting | ||
web_socket.send MSG1 | ||
echo := web_socket.receive | ||
expect_equals MSG1 echo | ||
web_socket.send MSG2 | ||
echo_bytes := web_socket.receive | ||
expect_equals MSG2 echo_bytes |