* Move src under playlet-lib * Update configuration * Update script * Update script * Working version * Vs code config WIP * Package lock sync * Lint fix * Fix images * Reuse config files * Kind of a working setup * Lock node version * Rename scripts to tools * Fix build scripts, lib url system * Lint fix * rale * Fix args and web server * Load fallbacks and build script cleanups * Remove unused method * no message * no message * Remove generic message field * Lint fix * no message * Use loading indicator on main app * Add playlet lib version to settings --------- Co-authored-by: github-action linter <githubaction@githubaction.com>
51 lines
1.6 KiB
Plaintext
51 lines
1.6 KiB
Plaintext
import "pkg:/source/utils/Crypto.bs"
|
|
|
|
namespace Http
|
|
|
|
const WEB_SOCKET_MAGIC_STRING = "258EAFA5-E914-47DA-95CA-C5AB0DC85B11"
|
|
|
|
class WebSocketMiddleware extends HttpRouter
|
|
|
|
function new()
|
|
super()
|
|
|
|
m.Get("*", function(context as object) as boolean
|
|
request = context.request
|
|
response = context.response
|
|
connection = context.connection
|
|
|
|
if LCase(validStr(request.headers["Connection"])) <> "upgrade"
|
|
return false
|
|
end if
|
|
|
|
if LCase(validStr(request.headers["Upgrade"])) <> "websocket"
|
|
return false
|
|
end if
|
|
|
|
webSocketKey = request.headers["Sec-WebSocket-Key"]
|
|
if webSocketKey = invalid
|
|
return false
|
|
end if
|
|
|
|
sha1Hash = GetSha1(webSocketKey + Http.WEB_SOCKET_MAGIC_STRING)
|
|
buffer = CreateObject("roByteArray")
|
|
buffer.FromHexString(sha1Hash)
|
|
webSocketAccept = ToBase64(buffer.ToAsciiString())
|
|
|
|
response.http_code = 101
|
|
response.headers["Connection"] = "Upgrade"
|
|
response.headers["Upgrade"] = "websocket"
|
|
response.headers["Sec-WebSocket-Accept"] = webSocketAccept
|
|
response.header_only = true
|
|
response.source = Http.HttpResponseSource.GENERATED
|
|
|
|
connection.ws_upgrade = true
|
|
|
|
return true
|
|
end function)
|
|
end function
|
|
|
|
end class
|
|
|
|
end namespace
|