Skip to content

Commit

Permalink
dont mask data to server per #176
Browse files Browse the repository at this point in the history
  • Loading branch information
samoconnor committed Jan 30, 2018
1 parent aaa6b20 commit f576d4d
Show file tree
Hide file tree
Showing 3 changed files with 86 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/WebSockets.jl
Original file line number Diff line number Diff line change
Expand Up @@ -185,8 +185,13 @@ function wswrite(ws::WebSocket, opcode::UInt8, bytes::Vector{UInt8})

n = length(bytes)
len, extended_len = wslength(n)
len |= WS_MASK
mask = mask!(ws.txpayload, bytes, n)
if ws.server
mask = UInt8[]
ws.txpayload = bytes
else
len |= WS_MASK
mask = mask!(ws.txpayload, bytes, n)
end

@debug 1 "WebSocket ⬅️ $(WebSocketHeader(opcode, len, extended_len, mask))"
write(ws.io, opcode, len, extended_len, mask)
Expand Down
38 changes: 38 additions & 0 deletions test/mwe.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<!DOCTYPE html>
<html>
<body>

<p id="status">?</p>

<button type="button" onclick="sayhello()">Say "Hello" to Julia</button>

<script>

var href = window.location.href;
var sock = new WebSocket("ws"+href.substr(4,href.length));
sock.onmessage = function( message ){
var msg = message.data;
document.getElementById("status").innerHTML = msg
console.log(msg);
}

sock.onopen = function () {
sock.send("Hello Julia! From JavaScript")
};

window.onbeforeunload = function() {
sock.onclose = function () {};
sock.close()
};

var count = 1

function sayhello() {
sock.send("Hello Julia! From JavaScript " + count)
count = count + 1
}

</script>

</body>
</html>
41 changes: 41 additions & 0 deletions test/mwe.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
using HTTP
using HTTP: hasheader

@static if is_apple()
launch(x) = run(`open $x`)
elseif is_linux()
launch(x) = run(`xdg-open $x`)
elseif is_windows()
launch(x) = run(`cmd /C start $x`)
end

@async begin
sleep(2)
launch("http://127.0.0.1:8000/examples/mwe")
end

HTTP.listen(ip"127.0.0.1",8000) do http
@show http
if http.message.method == "GET" &&
hasheader(http, "Connection", "upgrade") &&
hasheader(http, "Upgrade", "websocket")

HTTP.WebSockets.upgrade(http) do client
count = 1
while !eof(client);
msg = String(readavailable(client))
println(msg)
write(client, "Hello JavaScript! From Julia $count")
count += 1
end
end
else
HTTP.Servers.handle_request(http) do req::HTTP.Request
HTTP.Response(200,readstring(joinpath(dirname(@__FILE__),"mwe.html")))
end
end
end




0 comments on commit f576d4d

Please sign in to comment.