[Python-checkins] python/dist/src/Lib httplib.py,1.67,1.68

jhylton@users.sourceforge.net jhylton@users.sourceforge.net
Wed, 13 Nov 2002 09:27:46 -0800


Update of /cvsroot/python/python/dist/src/Lib
In directory usw-pr-cvs1:/tmp/cvs-serv12406

Modified Files:
	httplib.py 
Log Message:
Fix SF bug #637789: Handle Proxy-Connection header.

Also, remove unused local variable noted by pychecker.


Index: httplib.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/httplib.py,v
retrieving revision 1.67
retrieving revision 1.68
diff -C2 -d -r1.67 -r1.68
*** httplib.py	9 Nov 2002 05:08:06 -0000	1.67
--- httplib.py	13 Nov 2002 17:27:43 -0000	1.68
***************
*** 170,174 ****
                  # It's a continuation line.
                  list.append(line)
-                 x = self.dict[headerseen] + "\n " + line.strip()
                  self.addcontinue(headerseen, line.strip())
                  continue
--- 170,173 ----
***************
*** 312,329 ****
  
          # will the connection close at the end of the response?
!         conn = self.msg.getheader('connection')
!         if conn:
!             conn = conn.lower()
!             # a "Connection: close" will always close the connection. if we
!             # don't see that and this is not HTTP/1.1, then the connection will
!             # close unless we see a Keep-Alive header.
!             self.will_close = conn.find('close') != -1 or \
!                               ( self.version != 11 and \
!                                 not self.msg.getheader('keep-alive') )
!         else:
!             # for HTTP/1.1, the connection will always remain open
!             # otherwise, it will remain open IFF we see a Keep-Alive header
!             self.will_close = self.version != 11 and \
!                               not self.msg.getheader('keep-alive')
  
          # do we have a Content-Length?
--- 311,315 ----
  
          # will the connection close at the end of the response?
!         self.will_close = self._check_close()
  
          # do we have a Content-Length?
***************
*** 351,354 ****
--- 337,364 ----
             self.length is None:
              self.will_close = 1
+ 
+     def _check_close(self):
+         if self.version == 11:
+             # An HTTP/1.1 proxy is assumed to stay open unless
+             # explicitly closed.
+             conn = self.msg.getheader('connection')
+             if conn and conn.lower().find("close") >= 0:
+                 return True
+             return False
+ 
+         # An HTTP/1.0 response with a Connection header is probably
+         # the result of a confused proxy.  Ignore it.
+ 
+         # For older HTTP, Keep-Alive indiciates persistent connection.
+         if self.msg.getheader('keep-alive'):
+             return False
+         
+         # Proxy-Connection is a netscape hack.
+         pconn = self.msg.getheader('proxy-connection')
+         if pconn and pconn.lower().find("keep-alive") >= 0:
+             return False
+ 
+         # otherwise, assume it will close
+         return True
  
      def close(self):