Class: Faye::WebSocket::Draft76Parser

Inherits:
Draft75Parser show all
Defined in:
lib/faye/websocket/draft76_parser.rb

Instance Attribute Summary

Attributes inherited from Draft75Parser

#protocol

Instance Method Summary collapse

Methods inherited from Draft75Parser

#frame, #initialize

Constructor Details

This class inherits a constructor from Faye::WebSocket::Draft75Parser

Instance Method Details

#close(code = nil, reason = nil, &callback) ⇒ Object



49
50
51
52
53
54
# File 'lib/faye/websocket/draft76_parser.rb', line 49

def close(code = nil, reason = nil, &callback)
  return if @closed
  @socket.send([0xFF, 0x00]) if @closing
  @closed = true
  callback.call if callback
end

#handshake_responseObject



9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/faye/websocket/draft76_parser.rb', line 9

def handshake_response
  env = @socket.env
  signature = handshake_signature(env['rack.input'].read)
  
  upgrade =  "HTTP/1.1 101 Web Socket Protocol Handshake\r\n"
  upgrade << "Upgrade: WebSocket\r\n"
  upgrade << "Connection: Upgrade\r\n"
  upgrade << "Sec-WebSocket-Origin: #{env['HTTP_ORIGIN']}\r\n"
  upgrade << "Sec-WebSocket-Location: #{@socket.url}\r\n"
  upgrade << "\r\n"
  upgrade << signature if signature
  upgrade
end

#handshake_signature(head) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/faye/websocket/draft76_parser.rb', line 23

def handshake_signature(head)
  return nil if head.empty?
  env = @socket.env
  
  key1   = env['HTTP_SEC_WEBSOCKET_KEY1']
  value1 = number_from_key(key1) / spaces_in_key(key1)
  
  key2   = env['HTTP_SEC_WEBSOCKET_KEY2']
  value2 = number_from_key(key2) / spaces_in_key(key2)
  
  @handshake_complete = true
  
  Digest::MD5.digest(big_endian(value1) +
                     big_endian(value2) +
                     head)
end

#open?Boolean

Returns:

  • (Boolean)


40
41
42
# File 'lib/faye/websocket/draft76_parser.rb', line 40

def open?
  !!@handshake_complete
end

#parse(data) ⇒ Object



44
45
46
47
# File 'lib/faye/websocket/draft76_parser.rb', line 44

def parse(data)
  return super if @handshake_complete
  handshake_signature(data)
end

#versionObject



5
6
7
# File 'lib/faye/websocket/draft76_parser.rb', line 5

def version
  'hixie-76'
end