Class: WebSocket::ServerHandshake

Inherits:
Object
  • Object
show all
Defined in:
lib/websocket/server_handshake.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(headers = {}) ⇒ ServerHandshake

Returns a new instance of ServerHandshake.



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

def initialize(headers = {})
  @headers = headers
end

Instance Attribute Details

#headersObject (readonly)

Returns the value of attribute headers.



3
4
5
# File 'lib/websocket/server_handshake.rb', line 3

def headers
  @headers
end

Instance Method Details

#render(out) ⇒ Object



9
10
11
# File 'lib/websocket/server_handshake.rb', line 9

def render(out)
  out << to_data
end

#to_dataObject



13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/websocket/server_handshake.rb', line 13

def to_data
  data = "HTTP/1.1 101 Switching Protocols#{CRLF}"

  unless @headers.empty?
    data << @headers.map do |header, value|
      "#{header}: #{value}"
    end.join(CRLF) << CRLF
  end

  data << CRLF
  data
end