From 80500be00edbedee74d9498fa1015a7a8e35f0fa Mon Sep 17 00:00:00 2001 From: lkcl Date: Wed, 14 Jul 2010 20:27:02 +0100 Subject: [PATCH] finally got keepalive working properly even with lynx --- ProxyServer.py | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/ProxyServer.py b/ProxyServer.py index cc22f44..fcafc44 100644 --- a/ProxyServer.py +++ b/ProxyServer.py @@ -152,19 +152,23 @@ class ProxyServerRequestHandler(object): p = self.proxies[session] # send command - req = "%s %s %s\n" % (reqtype, self.hr.path, self.hr.request_version) + #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) + conntype = self.hr.headers.get('Connection', "") + keepalive = conntype.lower() == 'keep-alive' + + self.hr.headers['Connection'] = 'keep-alive' + self.hr.close_connection = 0 + # send headers hdrs = str(self.hr.headers) print "hdrs", hdrs yield p.ss.write(hdrs) yield p.ss.write('\r\n') - conntype = self.hr.headers.get('Connection', "") - keepalive = conntype.lower() == 'keep-alive' - # now content if self.hr.headers.has_key('content-length'): max_chunk_size = 10*1024*1024 @@ -256,13 +260,11 @@ class ProxyServerRequestHandler(object): break yield self.client.writeMessage(data) - raise StopIteration - - if self.hr.close_connection: + if not keepalive: #self.hr.close_connection: print 'proxy wants client to close_connection' try: - raise httpd.ConnectionClosed yield self.client.connectionClosed() + raise httpd.ConnectionClosed except httpd.ConnectionClosed: print 'close_connection done' pass -- 2.30.2