[Zope3-checkins] SVN: Zope3/trunk/src/zope/server/http/ when sending the header 'Connection: keep-alive' explicitly, 'Connection: close' was sent back. fixed it.

Jodok Batlogg jodok.batlogg at lovelysystems.com
Sun Mar 11 16:11:25 EDT 2007


Log message for revision 73143:
  when sending the header 'Connection: keep-alive' explicitly, 'Connection: close' was sent back. fixed it.
  

Changed:
  U   Zope3/trunk/src/zope/server/http/httptask.py
  U   Zope3/trunk/src/zope/server/http/tests/test_httpserver.py

-=-
Modified: Zope3/trunk/src/zope/server/http/httptask.py
===================================================================
--- Zope3/trunk/src/zope/server/http/httptask.py	2007-03-11 20:04:02 UTC (rev 73142)
+++ Zope3/trunk/src/zope/server/http/httptask.py	2007-03-11 20:11:25 UTC (rev 73143)
@@ -141,7 +141,9 @@
                 # Replying with headers only.
                 pass
             elif not ('Content-Length' in response_headers):
-                if 'content-length' not in (header.lower() for header in
+                # accumulated_headers is a simple list, we need to cut off
+                # the value of content-length manually
+                if 'content-length' not in (header[:14].lower() for header in
                     accumulated_headers):
                     close_it = 1                
             # under HTTP 1.1 keep-alive is default, no need to set the header

Modified: Zope3/trunk/src/zope/server/http/tests/test_httpserver.py
===================================================================
--- Zope3/trunk/src/zope/server/http/tests/test_httpserver.py	2007-03-11 20:04:02 UTC (rev 73142)
+++ Zope3/trunk/src/zope/server/http/tests/test_httpserver.py	2007-03-11 20:11:25 UTC (rev 73143)
@@ -345,6 +345,21 @@
         self.failUnlessEqual(int(response.status), 200)
         self.failUnless(response.getheader('connection') != 'close')
 
+        # Explicitly set keep-alive
+        data = "Default: Keep me alive"
+        s = ("GET / HTTP/1.1\n"
+             "Connection: keep-alive\n"
+             "Content-Length: %d\n"
+             "\n"
+             "%s") % (len(data), data)
+        sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
+        sock.connect((LOCALHOST, self.port))
+        sock.send(s)
+        response = ClientHTTPResponse(sock)
+        response.begin()
+        self.failUnlessEqual(int(response.status), 200)
+        self.failUnless(response.getheader('connection') != 'close')
+
         # no idea why the test publisher handles this request incorrectly
         # it would be less typing in the test :)
         # h = HTTPConnection(LOCALHOST, self.port)



More information about the Zope3-Checkins mailing list