11module WebSockets
22
3- using Base64, LoggingExtras, UUIDs, Sockets, Random
3+ using Base64, UUIDs, Sockets, Random
44using MbedTLS: digest, MD_SHA1, SSLContext
55using .. IOExtras, .. Streams, .. Connections, .. Messages, .. Conditions, .. Servers
66using .. Exceptions: current_exceptions_to_string
@@ -373,7 +373,7 @@ function open(f::Function, url; suppress_close_error::Bool=false, verbose=false,
373373 http. ntoread = 0
374374 io = http. stream
375375 ws = WebSocket (io, http. message. request, http. message; maxframesize, maxfragmentation)
376- @debugv 2 " $(ws. id) : WebSocket opened"
376+ @debug " $(ws. id) : WebSocket opened"
377377 try
378378 f (ws)
379379 catch e
@@ -423,7 +423,7 @@ listen(f, args...; kw...) = Servers.listen(http -> upgrade(f, http; kw...), args
423423listen! (f, args... ; kw... ) = Servers. listen! (http -> upgrade (f, http; kw... ), args... ; kw... )
424424
425425function upgrade (f:: Function , http:: Streams.Stream ; suppress_close_error:: Bool = false , maxframesize:: Integer = typemax (Int), maxfragmentation:: Integer = DEFAULT_MAX_FRAG, nagle= false , quickack= true , kw... )
426- @debugv 2 " Server websocket upgrade requested"
426+ @debug " Server websocket upgrade requested"
427427 isupgrade (http. message) || handshakeerror ()
428428 if ! hasheader (http, " Sec-WebSocket-Version" , " 13" )
429429 throw (WebSocketError (" Expected \" Sec-WebSocket-Version: 13\" !\n " * " $(http. message) " ))
@@ -451,7 +451,7 @@ function upgrade(f::Function, http::Streams.Stream; suppress_close_error::Bool=f
451451 end
452452
453453 ws = WebSocket (io, req, req. response; client= false , maxframesize, maxfragmentation)
454- @debugv 2 " $(ws. id) : WebSocket upgraded; connection established"
454+ @debug " $(ws. id) : WebSocket upgraded; connection established"
455455 try
456456 f (ws)
457457 catch e
@@ -511,7 +511,7 @@ or `close(ws[, body::WebSockets.CloseFrameBody])`. Calling `close` will initiate
511511the close sequence and close the underlying connection.
512512"""
513513function Sockets. send (ws:: WebSocket , x)
514- @debugv 2 " $(ws. id) : Writing non-control message"
514+ @debug " $(ws. id) : Writing non-control message"
515515 @require ! ws. writeclosed
516516 if ! isbinary (x) && ! istext (x)
517517 # if x is not single binary or text, then assume it's an iterable of binary or text
@@ -524,7 +524,7 @@ function Sockets.send(ws::WebSocket, x)
524524 x = " "
525525 @goto write_single_frame
526526 end
527- @debugv 2 " $(ws. id) : Writing fragmented message"
527+ @debug " $(ws. id) : Writing fragmented message"
528528 item, st = state
529529 # we prefetch next state so we know if we're on the last item or not
530530 # so we can appropriately set the FIN bit for the last fragmented frame
@@ -553,7 +553,7 @@ to when a PING message is received by a websocket connection.
553553"""
554554function ping (ws:: WebSocket , data= UInt8[])
555555 @require ! ws. writeclosed
556- @debugv 2 " $(ws. id) : sending ping"
556+ @debug " $(ws. id) : sending ping"
557557 return writeframe (ws. io, Frame (true , PING, ws. client, payload (ws, data)))
558558end
559559
@@ -568,7 +568,7 @@ used as a one-way heartbeat.
568568"""
569569function pong (ws:: WebSocket , data= UInt8[])
570570 @require ! ws. writeclosed
571- @debugv 2 " $(ws. id) : sending pong"
571+ @debug " $(ws. id) : sending pong"
572572 return writeframe (ws. io, Frame (true , PONG, ws. client, payload (ws, data)))
573573end
574574
@@ -584,7 +584,7 @@ frame.
584584"""
585585function Base. close (ws:: WebSocket , body:: CloseFrameBody = CloseFrameBody (1000 , " " ))
586586 isclosed (ws) && return
587- @debugv 2 " $(ws. id) : Closing websocket"
587+ @debug " $(ws. id) : Closing websocket"
588588 ws. writeclosed = true
589589 data = Vector {UInt8} (body. message)
590590 prepend! (data, reinterpret (UInt8, [hton (UInt16 (body. status))]))
@@ -676,10 +676,10 @@ returned by `receive`. Note that `WebSocket` objects can be iterated,
676676where each iteration yields a message until the connection is closed.
677677"""
678678function receive (ws:: WebSocket )
679- @debugv 2 " $(ws. id) : Reading message"
679+ @debug " $(ws. id) : Reading message"
680680 @require ! ws. readclosed
681681 frame = readframe (ws. io, Frame, ws. readbuffer)
682- @debugv 2 " $(ws. id) : Received frame: $frame "
682+ @debug " $(ws. id) : Received frame: $frame "
683683 done = checkreadframe! (ws, frame)
684684 # common case of reading single non-control frame
685685 done && return frame. payload
@@ -689,16 +689,16 @@ function receive(ws::WebSocket)
689689 payload = frame. payload
690690 while true
691691 frame = readframe (ws. io, Frame, ws. readbuffer, opcode)
692- @debugv 2 " $(ws. id) : Received frame: $frame "
692+ @debug " $(ws. id) : Received frame: $frame "
693693 done = checkreadframe! (ws, frame)
694694 if ! iscontrol (frame. flags. opcode)
695695 payload = _append (payload, frame. payload)
696- @debugv 2 " $(ws. id) : payload len = $(length (payload)) "
696+ @debug " $(ws. id) : payload len = $(length (payload)) "
697697 end
698698 done && break
699699 end
700700 payload isa String && utf8check (payload)
701- @debugv 2 " Read message: $(payload[1 : min (1024 , sizeof (payload))]) "
701+ @debug " Read message: $(payload[1 : min (1024 , sizeof (payload))]) "
702702 return payload
703703end
704704
0 commit comments