Make cookie finding in ws server a little more robust, put in some debugging

This commit is contained in:
Raphael 2010-11-04 13:34:27 -07:00
parent 152025f912
commit fbbb88109b

View file

@ -24,6 +24,10 @@ def write_pidfile
end
end
def debug_pp thing
pp thing if APP_CONFIG[:socket_debug] || ENV[:SOCKET_DEBUG]
end
CHANNEL = Magent::GenericChannel.new('websocket')
def process_message
if CHANNEL.queue_count > 0
@ -47,16 +51,26 @@ begin
:port => APP_CONFIG[:socket_port],
:debug =>APP_CONFIG[:socket_debug]) do |ws|
ws.onopen {
debug_pp ws.request
cookies = ws.request["Cookie"].split(';')
session_key = "_diaspora_session="
enc_diaspora_cookie = cookies.detect{|c| c.include?(session_key)}.gsub(session_key,'')
cookie = Marshal.load(enc_diaspora_cookie.unpack("m*").first)
debug_pp cookie
encoded_cookie = ws.request["Cookie"].gsub("_diaspora_session=","")
cookie = Marshal.load(encoded_cookie.unpack("m*").first)
user_id = cookie["warden.user.user.key"].last
debug_pp "In WSS, suscribing user: #{User.find(user_id).real_name} with id: #{user_id}"
sid = Diaspora::WebSocket.subscribe(user_id, ws)
ws.onmessage { |msg| SocketsController.new.incoming(msg) }
ws.onclose { Diaspora::WebSocket.unsubscribe(user_id, sid) }
ws.onclose {
debug_pp "In WSS, unsuscribing user: #{User.find(user_id).real_name} with id: #{user_id}"
Diaspora::WebSocket.unsubscribe(user_id, sid) }
}
end
PID_FILE = APP_CONFIG[:socket_pidfile]