diff --git a/src/WebSockets.jl b/src/WebSockets.jl index 9922d1f4c..9019f2052 100644 --- a/src/WebSockets.jl +++ b/src/WebSockets.jl @@ -56,6 +56,11 @@ end # Handshake +is_websocket_upgrade(r::HTTP.Message) = + (r isa HTTP.Request && r.method == "GET" || r.status == 101) && + HTTP.hasheader(r, "Connection", "upgrade") && + HTTP.hasheader(r, "Upgrade", "webscoket") + function check_upgrade(http) diff --git a/test/mwe.jl b/test/mwe.jl index e0d098197..810cb7909 100644 --- a/test/mwe.jl +++ b/test/mwe.jl @@ -17,10 +17,8 @@ end HTTP.listen(ip"127.0.0.1", 8000,; ssl = true, - sslconfig = MbedTLS.SSLConfig("cert.pem", "key.pem")) do http - if http.message.method == "GET" && - hasheader(http, "Connection", "upgrade") && - hasheader(http, "Upgrade", "websocket") + sslconfig = MbedTLS.SSLConfig(joinpath(dirname(@__FILE__),"cert.pem"), joinpath(dirname(@__FILE__),"key.pem"))) do http + if HTTP.WebSockets.is_websocket_upgrade(http.message) HTTP.WebSockets.upgrade(http) do client count = 1