experimentation
authorlkcl <lkcl@teenymac.(none)>
Wed, 14 Jul 2010 21:50:26 +0000 (22:50 +0100)
committerlkcl <lkcl@teenymac.(none)>
Wed, 14 Jul 2010 21:50:26 +0000 (22:50 +0100)
ProxyServer.py

index fcafc446e79ac215583448a3e57f57a471a553bb..dd10f75e1a6c8519b3968b1cc99eb541f06af07c 100644 (file)
@@ -44,6 +44,7 @@ class ProxyConnection:
     auto_open = 1
     debuglevel = 0
     strict = 0
+    serving = False
 
     def __init__(self):
         self.sock = None
@@ -124,6 +125,7 @@ class ProxyServerRequestHandler(object):
 
     def on_query(self, client, reqtype, *args):
         """Serve a request."""
+
         self.client = client
         self.hr = args[0]
         print "on_query", reqtype, repr(self.hr.headers), str(self.hr.headers)
@@ -151,8 +153,11 @@ class ProxyServerRequestHandler(object):
         session = self.client.session 
         p = self.proxies[session]
 
+        #while p.serving:
+        #    (yield multitask.sleep(0.01))
+        p.serving = True
+
         # send command
-        #req = "%s %s %s\n" % (reqtype, self.hr.path, self.hr.request_version)
         req = "%s %s %s\n" % (reqtype, self.hr.path, "HTTP/1.1")
         print "req", req
         yield p.ss.write(req)
@@ -184,8 +189,8 @@ class ProxyServerRequestHandler(object):
 
         # now read response and write back
         # HTTP/1.0 200 OK status line etc.
-        line = (yield p.ss.readline())
-        yield self.client.writeMessage(line)
+        responseline = (yield p.ss.readline())
+        yield self.client.writeMessage(responseline)
 
         res = ''
         try:
@@ -217,6 +222,12 @@ class ProxyServerRequestHandler(object):
         self.hr.response_cookies = rcooks
         print "rcooks", str(rcooks)
 
+        # override connection: keep-alive hack
+        #responseline = responseline.split(" ")
+        #print "responseline:", responseline
+        #if responseline[1] != "200":
+        #    respheaders['Connection'] = 'close'
+
         # send all but Set-Cookie headers
         del respheaders['Set-Cookie'] # being replaced
         yield self.client.writeMessage(str(respheaders))
@@ -269,5 +280,7 @@ class ProxyServerRequestHandler(object):
                 print 'close_connection done'
                 pass
 
+        p.serving = False
+
         raise StopIteration