class WebSocket::Handshake::Handler::Client04
Public Instance Methods
valid?()
click to toggle source
@see WebSocket::Handshake::Base#valid?
Calls superclass method
WebSocket::Handshake::Handler::Base#valid?
# File lib/websocket/handshake/handler/client04.rb, line 11 def valid? super && verify_accept && verify_protocol end
Private Instance Methods
accept()
click to toggle source
Value of Sec-WebSocket-Accept that should be delivered back by server @return [Sering] accept
# File lib/websocket/handshake/handler/client04.rb, line 42 def accept @accept ||= Base64.encode64(Digest::SHA1.digest(key + '258EAFA5-E914-47DA-95CA-C5AB0DC85B11')).strip end
handshake_keys()
click to toggle source
@see WebSocket::Handshake::Handler::Base#handshake_keys
Calls superclass method
WebSocket::Handshake::Handler::Client#handshake_keys
# File lib/websocket/handshake/handler/client04.rb, line 18 def handshake_keys keys = [ %w[Upgrade websocket], %w[Connection Upgrade] ] host = @handshake.host host += ":#{@handshake.port}" unless @handshake.default_port? keys << ['Host', host] keys += super keys << ['Sec-WebSocket-Origin', @handshake.origin] if @handshake.origin keys << ['Sec-WebSocket-Version', @handshake.version] keys << ['Sec-WebSocket-Key', key] keys << ['Sec-WebSocket-Protocol', @handshake.protocols.join(', ')] if @handshake.protocols.any? keys end
key()
click to toggle source
Sec-WebSocket-Key value @return [String] key
# File lib/websocket/handshake/handler/client04.rb, line 36 def key @key ||= Base64.encode64((1..16).map { rand(255).chr } * '').strip end
provided_protocols()
click to toggle source
# File lib/websocket/handshake/handler/client04.rb, line 57 def provided_protocols @handshake.headers['sec-websocket-protocol'].to_s.split(/ *, */) end
supported_protocols()
click to toggle source
# File lib/websocket/handshake/handler/client04.rb, line 53 def supported_protocols @handshake.protocols end
verify_accept()
click to toggle source
Verify if received header Sec-WebSocket-Accept matches generated one. @return [Boolean] True if accept is matching. False otherwise(appropriate error is set)
# File lib/websocket/handshake/handler/client04.rb, line 48 def verify_accept raise WebSocket::Error::Handshake::InvalidAuthentication unless @handshake.headers['sec-websocket-accept'] == accept true end