* Drm support * A few tweaks to http connection * changelog * changelog * add requires_widevine_drm to app manifest * movie renderer nodes * Small fix in header parsing
56 lines
1.8 KiB
Plaintext
56 lines
1.8 KiB
Plaintext
import "pkg:/components/Web/WebServer/Http/HttpRouter.bs"
|
|
import "pkg:/source/utils/CryptoUtils.bs"
|
|
import "pkg:/source/utils/StringUtils.bs"
|
|
import "pkg:/source/utils/Types.bs"
|
|
|
|
namespace Http
|
|
|
|
const WEB_SOCKET_MAGIC_STRING = "258EAFA5-E914-47DA-95CA-C5AB0DC85B11"
|
|
|
|
class WebSocketMiddleware extends HttpRouter
|
|
|
|
function new()
|
|
super()
|
|
end function
|
|
|
|
@get("*")
|
|
function HandleWebSocketHeaders(context as object) as boolean
|
|
request = context.request
|
|
response = context.response
|
|
connection = context.connection
|
|
|
|
if LCase(ValidString(request.headers["Connection"])) <> "upgrade"
|
|
return false
|
|
end if
|
|
|
|
if LCase(ValidString(request.headers["Upgrade"])) <> "websocket"
|
|
return false
|
|
end if
|
|
|
|
webSocketKey = request.headers["Sec-WebSocket-Key"]
|
|
if webSocketKey = invalid
|
|
return false
|
|
end if
|
|
|
|
sha1Hash = CryptoUtils.GetSha1(webSocketKey + Http.WEB_SOCKET_MAGIC_STRING)
|
|
buffer = CreateObject("roByteArray")
|
|
buffer.FromHexString(sha1Hash)
|
|
webSocketAccept = buffer.ToBase64String()
|
|
|
|
response.http_code = 101
|
|
response.headers["Connection"] = "Upgrade"
|
|
response.headers["Upgrade"] = "websocket"
|
|
response.headers["Sec-WebSocket-Accept"] = webSocketAccept
|
|
response.ClearBody()
|
|
|
|
' We want this connection to be upgraded to a WebSocket connection
|
|
' The connection will stop being handled by the HTTP server and will be handled by the WebSocket server
|
|
connection.ws_upgrade = true
|
|
|
|
return true
|
|
end function
|
|
|
|
end class
|
|
|
|
end namespace
|