From 3ba008c8a834bff394f5a1a81d4791d0764320ca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fredrik=20Sv=C3=A4rd?= Date: Wed, 13 Jul 2016 10:44:47 +0200 Subject: [PATCH] Make it possible to provide header information Make it possible to provide header information to client in case it's needed --- lib/socket.io-client-simple/client.rb | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/lib/socket.io-client-simple/client.rb b/lib/socket.io-client-simple/client.rb index d4a48ad..8f8a41d 100644 --- a/lib/socket.io-client-simple/client.rb +++ b/lib/socket.io-client-simple/client.rb @@ -2,8 +2,8 @@ module SocketIO module Client module Simple - def self.connect(url, opts={}) - client = Client.new(url, opts) + def self.connect(url, opts={}, headers={}) + client = Client.new(url, opts, headers) client.connect return client end @@ -15,9 +15,10 @@ class Client attr_accessor :auto_reconnection, :websocket, :url, :reconnecting, :state, :session_id, :ping_interval, :ping_timeout, :last_pong_at, :last_ping_at - def initialize(url, opts={}) + def initialize(url, opts={}, headers={}) @url = url @opts = opts + @headers = headers @opts[:transport] = :websocket @reconnecting = false @state = :disconnect @@ -49,7 +50,7 @@ def initialize(url, opts={}) def connect query = @opts.map{|k,v| URI.encode "#{k}=#{v}" }.join '&' begin - @websocket = WebSocket::Client::Simple.connect "#{@url}/socket.io/?#{query}" + @websocket = WebSocket::Client::Simple.connect "#{@url}/socket.io/?#{query}", options = @headers rescue Errno::ECONNREFUSED => e @state = :disconnect @reconnecting = false