From: lkcl Date: Tue, 13 Jul 2010 19:38:45 +0000 (+0100) Subject: make sure cookies are added to jsonrpc server responses X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=ab8a110d1c7d2cac2bf0928e5f51521cc62c6fcd;p=multitaskhttpd.git make sure cookies are added to jsonrpc server responses --- diff --git a/SimpleJSONRPCServer.py b/SimpleJSONRPCServer.py index 987503d..e85b44e 100644 --- a/SimpleJSONRPCServer.py +++ b/SimpleJSONRPCServer.py @@ -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: diff --git a/httpd.py b/httpd.py index 6537ee0..7b5e2a6 100644 --- 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