[Python-checkins] python/dist/src/Lib/test test_httplib.py, 1.12, 1.13

jhylton at users.sourceforge.net jhylton at users.sourceforge.net
Sat Aug 7 18:28:16 CEST 2004


Update of /cvsroot/python/python/dist/src/Lib/test
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv15119/test

Modified Files:
	test_httplib.py 
Log Message:
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.


Index: test_httplib.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/test/test_httplib.py,v
retrieving revision 1.12
retrieving revision 1.13
diff -C2 -d -r1.12 -r1.13
*** test_httplib.py	8 Jul 2003 12:36:58 -0000	1.12
--- test_httplib.py	7 Aug 2004 16:28:14 -0000	1.13
***************
*** 3,7 ****
  import sys
  
! from test.test_support import verify,verbose
  
  class FakeSocket:
--- 3,9 ----
  import sys
  
! from unittest import TestCase
! 
! from test import test_support
  
  class FakeSocket:
***************
*** 10,13 ****
--- 12,18 ----
          self.fileclass = fileclass
  
+     def sendall(self, data):
+         self.data = data
+ 
      def makefile(self, mode, bufsize=None):
          if mode != 'r' and mode != 'rb':
***************
*** 33,36 ****
--- 38,74 ----
          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
***************
*** 111,113 ****
--- 149,156 ----
      resp.close()
  
+ 
+ def test_main(verbose=None):
+     tests = [HeaderTests,]
+     test_support.run_unittest(*tests)
+ 
  test()



More information about the Python-checkins mailing list