import os, sys, time, struct, socket, traceback, multitask
import threading, Queue
import uuid
+from string import strip
from BaseHTTPServer import BaseHTTPRequestHandler
from SimpleAppHTTPServer import SimpleAppHTTPRequestHandler
from cStringIO import StringIO
from cookielib import parse_ns_headers, CookieJar
+from Cookie import SimpleCookie
_debug = False
def get_header(self, hdr, default):
return self.headers.getheader(hdr, default)
- def has_header(self, hdr):
- return False
-
- def is_unverifiable(self):
- return False
-
- def add_unredirected_header(self, name, val):
- if name == 'Cookie':
+ def add_cookies(self):
+ for k, v in self.response_cookies.items():
+ val = v.OutputString()
self.send_header("Set-Cookie", val)
class ConnectionClosed:
def messageReceived(self, msg):
if _debug: print 'messageReceived cmd=', msg.command, msg.path
ch = msg.headers.getheaders("Cookie")
- ch = parse_ns_headers(ch)
- cookies = self.cookies._cookies_from_attrs_set(ch, msg)
+ print "messageReceived cookieheaders=", '; '.join(ch)
+ res = []
+ for c in ch:
+ c = c.split(";")
+ c = map(strip, c)
+ res += c
has_sess = False
- for c in cookies:
- self.cookies.set_cookie(c)
- if c.name == "session":
+ msg.response_cookies = SimpleCookie()
+ for c in res:
+ print "found cookie", str(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]['expires'] = 'None'
+ msg.response_cookies[name]['version'] = 0
+ if name == "session":
has_sess = True
- msg.sess_cookie = c
if not has_sess:
- t = ("session", uuid.uuid4().hex, {}, {})
- msg.sess_cookie = self.cookies._cookie_from_cookie_tuple(t, msg)
- self.cookies.set_cookie(msg.sess_cookie)
+ 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
yield self.server.queue.put((self, msg)) # new connection
def accept(self):
yield client.rejectConnection(reason='Unsupported encoding ' + str(client.objectEncoding) + '. Please use NetConnection.defaultObjectEncoding=ObjectEncoding.AMF0')
yield client.connectionClosed()
else:
- print "cookies", str(client.cookies)
- session = msg.sess_cookie.value
+ print "cookies", str(msg.response_cookies)
+ session = msg.response_cookies['session'].value
name, ignore, scope = msg.path.partition('/')
if '*' not in self.apps and name not in self.apps:
yield client.rejectConnection(reason='Application not found: ' + name)
else: # create application instance as needed and add in our list
if _debug: print 'name=', name, 'name in apps', str(name in self.apps)
app = self.apps[name] if name in self.apps else self.apps['*'] # application class
+ print "clients", self.clients.keys()
if session in self.clients: inst = self.clients[session][0]
else: inst = app()
try: