Class: WebSocket::Driver::HTTPX

Inherits:
Hybi
  • Object
show all
Defined in:
lib/websocket/driver/httpx.rb

Overview

WebSocket driver with HTTPX handling the HTTP negotiation

Instance Method Summary collapse

Constructor Details

#initialize(socket, headers, options = {}) ⇒ HTTPX

Returns a new instance of HTTPX.



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/websocket/driver/httpx.rb', line 7

def initialize(socket, headers, options = {})
  super(socket, options)
  @headers = headers
  @closed = false

  @key = Client.generate_key
  @accept = Driver::Hybi.generate_accept(@key)

  @headers["upgrade"]               = "websocket"
  @headers["connection"]            = "Upgrade"
  @headers["sec-websocket-key"]     = @key
  @headers["sec-websocket-version"] = VERSION

  @headers["Sec-WebSocket-Protocol"] = @protocols * ", " if @protocols.size.positive?

  extensions = @extensions.generate_offer
  @headers["Sec-WebSocket-Extensions"] = extensions if extensions
end

Instance Method Details

#runObject



31
32
33
34
35
36
37
38
39
40
41
# File 'lib/websocket/driver/httpx.rb', line 31

def run
  closed = false
  on(:close) do
    closed = true
  end

  until closed
    bytes = @socket.read(1)
    parse(bytes)
  end
end

#startObject



26
27
28
29
# File 'lib/websocket/driver/httpx.rb', line 26

def start
  open
  parse(@initial_response)
end