From: lkcl Date: Wed, 14 Jul 2010 21:50:26 +0000 (+0100) Subject: experimentation X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=b3d66ab8f2472a2768ab4529f0a81a1013da15d6;p=multitaskhttpd.git experimentation --- diff --git a/ProxyServer.py b/ProxyServer.py index fcafc44..dd10f75 100644 --- a/ProxyServer.py +++ b/ProxyServer.py @@ -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