Fix SF bug 525520.
Don't automatically add a Host: header if the headers passed to request() already has a Host key.
This commit is contained in:
parent
dc5a508761
commit
3921ff675e
|
@ -410,7 +410,7 @@ class HTTPConnection:
|
|||
self.close()
|
||||
raise
|
||||
|
||||
def putrequest(self, method, url):
|
||||
def putrequest(self, method, url, skip_host=0):
|
||||
"""Send a request to the server.
|
||||
|
||||
`method' specifies an HTTP request method, e.g. 'GET'.
|
||||
|
@ -461,22 +461,29 @@ class HTTPConnection:
|
|||
if self._http_vsn == 11:
|
||||
# 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 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.
|
||||
# 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:'):
|
||||
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', netloc)
|
||||
self.putheader('Host', self.host)
|
||||
else:
|
||||
self.putheader('Host', "%s:%s" % (self.host, self.port))
|
||||
|
||||
|
@ -536,6 +543,13 @@ class HTTPConnection:
|
|||
self._send_request(method, url, body, headers)
|
||||
|
||||
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:
|
||||
|
|
Loading…
Reference in New Issue