class WebSocket::Handshake::Handler::Server04

Public Instance Methods

valid?() click to toggle source

@see WebSocket::Handshake::Base#valid?

# File lib/websocket/handshake/handler/server04.rb, line 11
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 23
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 18
def header_line
  'HTTP/1.1 101 Switching Protocols'
end
key() click to toggle source
# File lib/websocket/handshake/handler/server04.rb, line 44
def key
  @handshake.headers['sec-websocket-key']
end
protocol() click to toggle source
# File lib/websocket/handshake/handler/server04.rb, line 48
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 33
def signature
  return unless key
  string_to_sign = "#{key}258EAFA5-E914-47DA-95CA-C5AB0DC85B11"
  Base64.encode64(Digest::SHA1.digest(string_to_sign)).chomp
end
verify_key() click to toggle source
# File lib/websocket/handshake/handler/server04.rb, line 39
def verify_key
  raise WebSocket::Error::Handshake::InvalidAuthentication unless key
  true
end