summaryrefslogtreecommitdiff
path: root/Lib/httplib.py
diff options
context:
space:
mode:
authorJeremy Hylton <jeremy@alum.mit.edu>2004-08-07 16:28:14 +0000
committerJeremy Hylton <jeremy@alum.mit.edu>2004-08-07 16:28:14 +0000
commite50ca5d513b5f41e91c34d9565b9a4438f8911f9 (patch)
tree18a234314489ba7f883c71c46eaf3411d7cd369b /Lib/httplib.py
parentb043545bad50d09c50773c6314ca55749f1ead6a (diff)
downloadcpython-e50ca5d513b5f41e91c34d9565b9a4438f8911f9.tar.gz
SF bug 874842 and patch 997626: httplib bugs
Hack httplib to work with broken Akamai proxies. Make sure that httplib doesn't add extract Accept-Encoding or Content-Length headers if the client has already set them.
Diffstat (limited to 'Lib/httplib.py')
-rw-r--r--Lib/httplib.py30
1 files changed, 20 insertions, 10 deletions
diff --git a/Lib/httplib.py b/Lib/httplib.py
index 5133c8dbe5..c0d372ff7e 100644
--- a/Lib/httplib.py
+++ b/Lib/httplib.py
@@ -344,6 +344,7 @@ class HTTPResponse:
self.will_close = 1
def _check_close(self):
+ conn = self.msg.getheader('connection')
if self.version == 11:
# An HTTP/1.1 proxy is assumed to stay open unless
# explicitly closed.
@@ -352,13 +353,18 @@ class HTTPResponse:
return True
return False
- # An HTTP/1.0 response with a Connection header is probably
- # the result of a confused proxy. Ignore it.
+ # Some HTTP/1.0 implementations have support for persistent
+ # connections, using rules different than HTTP/1.1.
# For older HTTP, Keep-Alive indiciates persistent connection.
if self.msg.getheader('keep-alive'):
return False
+ # At least Akamai returns a "Connection: Keep-Alive" header,
+ # which was supposed to be sent by the client.
+ if conn and "keep-alive" in conn.lower():
+ return False
+
# Proxy-Connection is a netscape hack.
pconn = self.msg.getheader('proxy-connection')
if pconn and "keep-alive" in pconn.lower():
@@ -381,6 +387,8 @@ class HTTPResponse:
# called, meaning self.isclosed() is meaningful.
return self.fp is None
+ # XXX It would be nice to have readline and __iter__ for this, too.
+
def read(self, amt=None):
if self.fp is None:
return ''
@@ -728,15 +736,17 @@ 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 'host' in [k.lower() for k in headers]:
- self.putrequest(method, url, skip_host=1)
- else:
- self.putrequest(method, url)
+ # honour explicitly requested Host: and Accept-Encoding headers
+ header_names = dict.fromkeys([k.lower() for k in headers])
+ skips = {}
+ if 'host' in header_names:
+ skips['skip_host'] = 1
+ if 'accept-encoding' in header_names:
+ skips['skip_accept_encoding'] = 1
- if body:
+ self.putrequest(method, url, **skips)
+
+ if body and ('content-length' not in header_names):
self.putheader('Content-Length', str(len(body)))
for hdr, value in headers.iteritems():
self.putheader(hdr, value)