[Python-checkins] python/dist/src/Lib httplib.py,1.77,1.78

gstein@users.sourceforge.net gstein@users.sourceforge.net
Mon, 23 Jun 2003 23:35:21 -0700


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

Modified Files:
	httplib.py 
Log Message:
Deal with a couple XXX comments which asked questions.

In response to "shouldn't the client close the file?", the answer is
"no". The original design behind HTTPConnection is that the client did
not have to worry about it. The response would close itself when you
read the last of the data from it. This closing also dealt with
allowing the connection to perform another request/response (if it was
a persistent connection).

However... the auto-close behavior broke compatibility with the
classic httplib.HTTP class' behavior when a zero-length response body
was present. In that situation, the HTTPResponse object was
auto-closing it since there was no data present, and for an HTTP/1.0
connection-close socket (or an HTTP/0.9 request) connection, that also
ended up closing the socket. When an httplib.HTTP user went to read
the socket... boom. A patch to correct the auto-close (for compat with
old httplib users) was added in rev 1.22.

But for non-zero-length *chunked* bodies, we should keep the
auto-close behavior. The library user is not reading the socket (they
can't cuz of the chunked response we just got done handling), so they
should be immune to the response closing the socket. In fact, I would
like to see (one day) the auto-close restored, and the HTTP subclass
would simply have a flag to disable that behavior (for back-compat
purposes).


Index: httplib.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/httplib.py,v
retrieving revision 1.77
retrieving revision 1.78
diff -C2 -d -r1.77 -r1.78
*** httplib.py	14 Jun 2003 13:30:53 -0000	1.77
--- httplib.py	24 Jun 2003 06:35:19 -0000	1.78
***************
*** 450,454 ****
  
          # we read everything; close the "file"
-         # XXX Shouldn't the client close the file?
          self.close()
  
--- 450,453 ----
***************
*** 601,606 ****
          """
  
!         # check if a prior response has been completed
!         # XXX What if it hasn't?
          if self.__response and self.__response.isclosed():
              self.__response = None
--- 600,604 ----
          """
  
!         # if a prior response has been completed, then forget about it.
          if self.__response and self.__response.isclosed():
              self.__response = None
***************
*** 744,748 ****
          "Get the response from the server."
  
!         # check if a prior response has been completed
          if self.__response and self.__response.isclosed():
              self.__response = None
--- 742,746 ----
          "Get the response from the server."
  
!         # if a prior response has been completed, then forget about it.
          if self.__response and self.__response.isclosed():
              self.__response = None