[Python-checkins] CVS: python/dist/src/Lib httplib.py,1.42.10.2,1.42.10.3

Michael Hudson mwh@users.sourceforge.net
Mon, 11 Mar 2002 02:19:18 -0800


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

Modified Files:
      Tag: release22-maint
	httplib.py 
Log Message:
I *think* this should go in.  May be wrong -- please howl in protest 
if so.

backport jhylton's checkin of
    revision 1.46 of httplib.py

Fix SF bug 525520.

Don't automatically add a Host: header if the headers passed to
request() already has a Host key.


Index: httplib.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/httplib.py,v
retrieving revision 1.42.10.2
retrieving revision 1.42.10.3
diff -C2 -d -r1.42.10.2 -r1.42.10.3
*** httplib.py	11 Mar 2002 10:06:36 -0000	1.42.10.2
--- httplib.py	11 Mar 2002 10:19:16 -0000	1.42.10.3
***************
*** 411,415 ****
              raise
  
!     def putrequest(self, method, url):
          """Send a request to the server.
  
--- 411,415 ----
              raise
  
!     def putrequest(self, method, url, skip_host=0):
          """Send a request to the server.
  
***************
*** 462,483 ****
              # Issue some standard headers for better HTTP/1.1 compliance
  
!             # this header is issued *only* for HTTP/1.1 connections. more
!             # specifically, this means it is only issued when the client uses
!             # the new HTTPConnection() class. backwards-compat clients will
!             # be using HTTP/1.0 and those clients may be issuing this header
!             # themselves. we should NOT issue it twice; some web servers (such
!             # as Apache) barf when they see two Host: headers
  
!             # If we need a non-standard port,include it in the header.
!             # If the request is going through a proxy, but the host of
!             # the actual URL, not the host of the proxy.
  
!             if url.startswith('http:'):
!                 nil, netloc, nil, nil, nil = urlsplit(url)
!                 self.putheader('Host', netloc)
!             elif self.port == HTTP_PORT:
!                 self.putheader('Host', netloc)
!             else:
!                 self.putheader('Host', "%s:%s" % (self.host, self.port))
  
              # note: we are assuming that clients will not attempt to set these
--- 462,490 ----
              # Issue some standard headers for better HTTP/1.1 compliance
  
!             if not skip_host:
!                 # this header is issued *only* for HTTP/1.1
!                 # connections. more specifically, this means it is
!                 # only issued when the client uses the new
!                 # HTTPConnection() class. backwards-compat clients
!                 # will be using HTTP/1.0 and those clients may be
!                 # issuing this header themselves. we should NOT issue
!                 # it twice; some web servers (such as Apache) barf
!                 # when they see two Host: headers
  
!                 # If we need a non-standard port,include it in the
!                 # header.  If the request is going through a proxy,
!                 # but the host of the actual URL, not the host of the
!                 # proxy.
  
!                 netloc = ''
!                 if url.startswith('http'):
!                     nil, netloc, nil, nil, nil = urlsplit(url)
! 
!                 if netloc:
!                     self.putheader('Host', netloc)
!                 elif self.port == HTTP_PORT:
!                     self.putheader('Host', self.host)
!                 else:
!                     self.putheader('Host', "%s:%s" % (self.host, self.port))
  
              # note: we are assuming that clients will not attempt to set these
***************
*** 537,541 ****
  
      def _send_request(self, method, url, body, headers):
!         self.putrequest(method, url)
  
          if body:
--- 544,555 ----
  
      def _send_request(self, method, url, body, headers):
!         # If headers already contains a host header, then define the
!         # optional skip_host argument to putrequest().  The check is
!         # harder because field names are case insensitive.
!         if (headers.has_key('Host')
!             or [k for k in headers.iterkeys() if k.lower() == "host"]):
!             self.putrequest(method, url, skip_host=1)
!         else:
!             self.putrequest(method, url)
  
          if body: