Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only copy String bytes if masked #93

Merged
merged 1 commit into from
Feb 21, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions src/WebSockets.jl
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,12 @@ function write_fragment(io::IO, islast::Bool, opcode, hasmask::Bool, data::Vecto
else
error("Attempted to send too much data for one websocket fragment\n")
end
hasmask && write(io,mask!(data))
if hasmask
if opcode == OPCODE_TEXT
data = copy(data) # Avoid masking Strings bytes in place
end
write(io,mask!(data))
end
write(io, data)
end

Expand All @@ -173,7 +178,7 @@ end

""" Write text data; will be sent as one frame."""
function Base.write(ws::WebSocket,data::String)
locked_write(ws.socket, true, OPCODE_TEXT, !ws.server, copy(Vector{UInt8}(data))) # Remove this `copy` after v0.7!
locked_write(ws.socket, true, OPCODE_TEXT, !ws.server, Vector{UInt8}(data)) # Vector{UInt8}(String) will give a warning in v0.7.
end

""" Write binary data; will be sent as one frame."""
Expand Down