Method: DigitalFabric::AgentProxy#handle_websocket_upgrade

Defined in:
lib/tipi/digital_fabric/agent_proxy.rb

#handle_websocket_upgrade(req) ⇒ Object



288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
# File 'lib/tipi/digital_fabric/agent_proxy.rb', line 288

def handle_websocket_upgrade(req)
  with_request do |id|
    send_df_message(Protocol.ws_request(id, req.headers))
    response = receive
    case response[0]
    when Protocol::WS_RESPONSE
      headers = response[2] || {}
      status = headers[':status'] || Qeweney::Status::SWITCHING_PROTOCOLS
      if status != Qeweney::Status::SWITCHING_PROTOCOLS
        req.respond(nil, headers)
        return
      end
      ws = Tipi::Websocket.new(req.adapter.conn, req.headers)
      run_websocket_connection(id, ws)
    else
      req.respond(nil, ':status' => Qeweney::Status::SERVICE_UNAVAILABLE)
    end
  end
rescue IOError, SystemCallError
  # ignore
end