class WebSocket::Handshake::Handler::Server04
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/server04.rb, line 10 def valid? super && verify_key end
Private Instance Methods
handshake_keys()
click to toggle source
@see WebSocket::Handshake::Handler::Base#handshake_keys
# File lib/websocket/handshake/handler/server04.rb, line 22 def handshake_keys [ %w[Upgrade websocket], %w[Connection Upgrade], ['Sec-WebSocket-Accept', signature] ] + protocol end
header_line()
click to toggle source
@see WebSocket::Handshake::Handler::Base#header_line
# File lib/websocket/handshake/handler/server04.rb, line 17 def header_line 'HTTP/1.1 101 Switching Protocols' end
key()
click to toggle source
# File lib/websocket/handshake/handler/server04.rb, line 43 def key @handshake.headers['sec-websocket-key'] end
protocol()
click to toggle source
# File lib/websocket/handshake/handler/server04.rb, line 47 def protocol return [] unless @handshake.headers.key?('sec-websocket-protocol') protos = @handshake.headers['sec-websocket-protocol'].split(/ *, */) & @handshake.protocols [['Sec-WebSocket-Protocol', protos.first]] end
signature()
click to toggle source
Signature of response, created from client request Sec-WebSocket-Key @return [String] signature
# File lib/websocket/handshake/handler/server04.rb, line 32 def signature return unless key string_to_sign = "#{key}258EAFA5-E914-47DA-95CA-C5AB0DC85B11" [Digest::SHA1.digest(string_to_sign)].pack('m').chomp end
verify_key()
click to toggle source
# File lib/websocket/handshake/handler/server04.rb, line 38 def verify_key raise WebSocket::Error::Handshake::InvalidAuthentication unless key true end