finally got keepalive working properly even with lynx
authorlkcl <lkcl@teenymac.(none)>
Wed, 14 Jul 2010 19:27:02 +0000 (20:27 +0100)
committerlkcl <lkcl@teenymac.(none)>
Wed, 14 Jul 2010 19:27:02 +0000 (20:27 +0100)
ProxyServer.py

index cc22f4476f9a165db2988ab0ab91c883281aac14..fcafc446e79ac215583448a3e57f57a471a553bb 100644 (file)
@@ -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