From fbbb88109bfc33791465e3f6a8f8642cd3c39a22 Mon Sep 17 00:00:00 2001 From: Raphael Date: Thu, 4 Nov 2010 13:34:27 -0700 Subject: [PATCH] Make cookie finding in ws server a little more robust, put in some debugging --- script/websocket_server.rb | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/script/websocket_server.rb b/script/websocket_server.rb index cc788e734..3cde39634 100644 --- a/script/websocket_server.rb +++ b/script/websocket_server.rb @@ -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]