make sure cookies are added to jsonrpc server responses
authorlkcl <lkcl@teenymac.(none)>
Tue, 13 Jul 2010 19:38:45 +0000 (20:38 +0100)
committerlkcl <lkcl@teenymac.(none)>
Tue, 13 Jul 2010 19:38:45 +0000 (20:38 +0100)
SimpleJSONRPCServer.py
httpd.py

index 987503d27e8cbe0ad48d03fa4d3324c5c33b0654..e85b44e41fbe9dc47f75c1c39cbec81c37c54e8a 100644 (file)
@@ -97,12 +97,14 @@ class SimpleJSONRPCRequestHandler(SimpleAppHTTPServer.SimpleAppHTTPRequestHandle
         except: # This should only happen if the module is buggy
             # internal error, report as HTTP server error
             self.hr.send_response(500)
+            self.hr.add_cookies()
             self.hr.end_headers()
         else:
             # got a valid JSONRPC response
             self.hr.send_response(200)
             self.hr.send_header("Content-type", "text/x-json")
             self.hr.send_header("Content-length", str(len(response)))
+            self.hr.add_cookies()
             self.hr.end_headers()
             self.hr.wfile.write(response)
 
@@ -116,6 +118,7 @@ class SimpleJSONRPCRequestHandler(SimpleAppHTTPServer.SimpleAppHTTPRequestHandle
         response = 'No such page'
         self.hr.send_header("Content-type", "text/plain")
         self.hr.send_header("Content-length", str(len(response)))
+        self.hr.add_cookies()
         self.hr.end_headers()
         self.hr.wfile.write(response)
         # shut down the connection
@@ -139,7 +142,7 @@ class SimpleJSONRPCRequestHandler(SimpleAppHTTPServer.SimpleAppHTTPRequestHandle
         try:
             req = cjson.decode(data)
             method = req['method']
-            params = req['params']
+            params = req['params'] or ()
             id     = req['id']
 
             if dispatch_method is not None:
index 6537ee0e6071358815a45bd18765dd269ff50155..7b5e2a61c98a7fd60c8eeb386154bbd6a63a15a7 100644 (file)
--- a/httpd.py
+++ b/httpd.py
@@ -468,30 +468,34 @@ class Client(Protocol):
     def messageReceived(self, msg):
         if _debug: print 'messageReceived cmd=', msg.command, msg.path
         ch = msg.headers.getheaders("Cookie")
+        ch += msg.headers.getheaders("cookie")
         print "messageReceived cookieheaders=", '; '.join(ch)
         res = []
         for c in ch:
             c = c.split(";")
+            if len(c) == 0:
+                continue
             c = map(strip, c)
+            c = filter(lambda x: x, c)
             res += c
         has_sess = False
         msg.response_cookies = SimpleCookie()
         for c in res:
-            print "found cookie", str(c)
+            print "found cookie", repr(c)
             name, value = c.split("=")
             msg.response_cookies[name] = value
-            msg.response_cookies[name]['path'] = "/"
-            msg.response_cookies[name]['domain'] = self.remote[0]
+            #msg.response_cookies[name]['path'] = "/"
+            #msg.response_cookies[name]['domain'] = self.remote[0]
             #msg.response_cookies[name]['expires'] = 'None'
-            msg.response_cookies[name]['version'] = 0
+            #msg.response_cookies[name]['version'] = 0
             if name == "session":
                 has_sess = True
         if not has_sess:
             msg.response_cookies['session'] = uuid.uuid4().hex
             #msg.response_cookies['session']['expires'] = 'None'
-            msg.response_cookies['session']['path'] = '/'
-            msg.response_cookies['session']['domain'] = self.remote[0]
-            msg.response_cookies['session']['version'] = 0
+            #msg.response_cookies['session']['path'] = '/'
+            #msg.response_cookies['session']['domain'] = self.remote[0]
+            #msg.response_cookies['session']['version'] = 0
 
         if msg.headers.has_key('content-length'):
             max_chunk_size = 10*1024*1024