mirror of
https://github.com/lune-org/lune.git
synced 2024-12-13 13:30:38 +00:00
Add TLS support for net.socket()
, fix WebSocket.closeCode
behavior (#57)
This commit is contained in:
parent
2169acb3d2
commit
aaa0977d54
5 changed files with 43 additions and 3 deletions
16
Cargo.lock
generated
16
Cargo.lock
generated
|
@ -1749,7 +1749,7 @@ dependencies = [
|
||||||
"wasm-bindgen",
|
"wasm-bindgen",
|
||||||
"wasm-bindgen-futures",
|
"wasm-bindgen-futures",
|
||||||
"web-sys",
|
"web-sys",
|
||||||
"webpki-roots",
|
"webpki-roots 0.22.6",
|
||||||
"winreg",
|
"winreg",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
@ -2361,8 +2361,11 @@ checksum = "ec509ac96e9a0c43427c74f003127d953a265737636129424288d27cb5c4b12c"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"futures-util",
|
"futures-util",
|
||||||
"log",
|
"log",
|
||||||
|
"rustls",
|
||||||
"tokio",
|
"tokio",
|
||||||
|
"tokio-rustls",
|
||||||
"tungstenite",
|
"tungstenite",
|
||||||
|
"webpki-roots 0.23.1",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
@ -2459,10 +2462,12 @@ dependencies = [
|
||||||
"httparse",
|
"httparse",
|
||||||
"log",
|
"log",
|
||||||
"rand",
|
"rand",
|
||||||
|
"rustls",
|
||||||
"sha1 0.10.5",
|
"sha1 0.10.5",
|
||||||
"thiserror",
|
"thiserror",
|
||||||
"url",
|
"url",
|
||||||
"utf-8",
|
"utf-8",
|
||||||
|
"webpki",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
@ -2684,6 +2689,15 @@ dependencies = [
|
||||||
"webpki",
|
"webpki",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "webpki-roots"
|
||||||
|
version = "0.23.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "b03058f88386e5ff5310d9111d53f48b17d732b401aeb83a8d5190f2ac459338"
|
||||||
|
dependencies = [
|
||||||
|
"rustls-webpki",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "winapi"
|
name = "winapi"
|
||||||
version = "0.3.9"
|
version = "0.3.9"
|
||||||
|
|
|
@ -52,7 +52,7 @@ async-compression = { version = "0.4", features = [
|
||||||
] }
|
] }
|
||||||
hyper = { version = "0.14", features = ["full"] }
|
hyper = { version = "0.14", features = ["full"] }
|
||||||
hyper-tungstenite = { version = "0.10" }
|
hyper-tungstenite = { version = "0.10" }
|
||||||
tokio-tungstenite = { version = "0.19" }
|
tokio-tungstenite = { version = "0.19", features = ["rustls-tls-webpki-roots"] }
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
anyhow = "1.0"
|
anyhow = "1.0"
|
||||||
|
|
|
@ -35,7 +35,7 @@ return freeze(setmetatable({
|
||||||
}, {
|
}, {
|
||||||
__index = function(self, key)
|
__index = function(self, key)
|
||||||
if key == "closeCode" then
|
if key == "closeCode" then
|
||||||
return close_code()
|
return close_code(websocket)
|
||||||
end
|
end
|
||||||
end,
|
end,
|
||||||
}))
|
}))
|
||||||
|
|
|
@ -57,6 +57,7 @@ create_tests! {
|
||||||
net_url_decode: "net/url/decode",
|
net_url_decode: "net/url/decode",
|
||||||
net_serve_requests: "net/serve/requests",
|
net_serve_requests: "net/serve/requests",
|
||||||
net_serve_websockets: "net/serve/websockets",
|
net_serve_websockets: "net/serve/websockets",
|
||||||
|
net_socket_wss: "net/socket/wss",
|
||||||
|
|
||||||
process_args: "process/args",
|
process_args: "process/args",
|
||||||
process_cwd: "process/cwd",
|
process_cwd: "process/cwd",
|
||||||
|
|
25
tests/net/socket/wss.luau
Normal file
25
tests/net/socket/wss.luau
Normal file
|
@ -0,0 +1,25 @@
|
||||||
|
local net = require("@lune/net")
|
||||||
|
local stdio = require("@lune/stdio")
|
||||||
|
local task = require("@lune/task")
|
||||||
|
|
||||||
|
-- net.socket() will inherently spit out an error if init connection fails, but for
|
||||||
|
-- the sake of this test, prot. call checks are unnecessary. Also, we're going to use
|
||||||
|
-- Discord's WebSocket gateway server for soley testing wss, as we don't need to auth
|
||||||
|
-- or anything for that; we just want to make sure it functions..
|
||||||
|
print("Connecting to Discord wss gateway..")
|
||||||
|
local socket = net.socket("wss://gateway.discord.gg/?v=10&encoding=json")
|
||||||
|
print("Connected!") -- Would've errored at net.socket() call before this if init connection err
|
||||||
|
|
||||||
|
while not socket.closeCode do
|
||||||
|
local nextMessage = socket.next()
|
||||||
|
|
||||||
|
if nextMessage then
|
||||||
|
print(`{stdio.style("bold")}Discord:{stdio.style("reset")}`, nextMessage)
|
||||||
|
|
||||||
|
print("Will (deliberately) close the socket in 2 seconds..")
|
||||||
|
task.wait(2)
|
||||||
|
socket.close(1000)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
print(`Connection to socket closed with closeCode {socket.closeCode}`)
|
Loading…
Reference in a new issue