diff options
author | Jeremy Hylton <jeremy@alum.mit.edu> | 2004-08-07 16:28:14 (GMT) |
---|---|---|
committer | Jeremy Hylton <jeremy@alum.mit.edu> | 2004-08-07 16:28:14 (GMT) |
commit | 2c178253bd1f78545d412670c59060dc7c676f8c (patch) | |
tree | c2a5d90890c84b0c13020bab96f64de0444a2a9a /Lib/test/test_httplib.py | |
parent | dc54f2be3f718cdd5208894b0d763d62f43ea3a5 (diff) | |
download | cpython-2c178253bd1f78545d412670c59060dc7c676f8c.zip cpython-2c178253bd1f78545d412670c59060dc7c676f8c.tar.gz cpython-2c178253bd1f78545d412670c59060dc7c676f8c.tar.bz2 |
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/test/test_httplib.py')
-rw-r--r-- | Lib/test/test_httplib.py | 45 |
1 files changed, 44 insertions, 1 deletions
diff --git a/Lib/test/test_httplib.py b/Lib/test/test_httplib.py index c57793d..5f252bb 100644 --- a/Lib/test/test_httplib.py +++ b/Lib/test/test_httplib.py @@ -2,13 +2,18 @@ import httplib import StringIO import sys -from test.test_support import verify,verbose +from unittest import TestCase + +from test import test_support class FakeSocket: def __init__(self, text, fileclass=StringIO.StringIO): self.text = text self.fileclass = fileclass + def sendall(self, data): + self.data = data + def makefile(self, mode, bufsize=None): if mode != 'r' and mode != 'rb': raise httplib.UnimplementedFileMode() @@ -32,6 +37,39 @@ class NoEOFStringIO(StringIO.StringIO): raise AssertionError('caller tried to read past EOF') return data + +class HeaderTests(TestCase): + def test_auto_headers(self): + # Some headers are added automatically, but should not be added by + # .request() if they are explicitly set. + + import httplib + + class HeaderCountingBuffer(list): + def __init__(self): + self.count = {} + def append(self, item): + kv = item.split(':') + if len(kv) > 1: + # item is a 'Key: Value' header string + lcKey = kv[0].lower() + self.count.setdefault(lcKey, 0) + self.count[lcKey] += 1 + list.append(self, item) + + for explicit_header in True, False: + for header in 'Content-length', 'Host', 'Accept-encoding': + conn = httplib.HTTPConnection('example.com') + conn.sock = FakeSocket('blahblahblah') + conn._buffer = HeaderCountingBuffer() + + body = 'spamspamspam' + headers = {} + if explicit_header: + headers[header] = str(len(body)) + conn.request('POST', '/', body, headers) + self.assertEqual(conn._buffer.count[header.lower()], 1) + # Collect output to a buffer so that we don't have to cope with line-ending # issues across platforms. Specifically, the headers will have \r\n pairs # and some platforms will strip them from the output file. @@ -110,4 +148,9 @@ def _test(): raise AssertionError, "Did not expect response from HEAD request" resp.close() + +def test_main(verbose=None): + tests = [HeaderTests,] + test_support.run_unittest(*tests) + test() |