Back to index

python3.2  3.2.2
Public Member Functions | Public Attributes
test.test_httplib.HeaderTests Class Reference
Inheritance diagram for test.test_httplib.HeaderTests:
Inheritance graph
[legend]
Collaboration diagram for test.test_httplib.HeaderTests:
Collaboration graph
[legend]

List of all members.

Public Member Functions

def test_auto_headers
def test_putheader
def test_ipv6host_header

Public Attributes

 count

Detailed Description

Definition at line 72 of file test_httplib.py.


Member Function Documentation

Definition at line 73 of file test_httplib.py.

00073 
00074     def test_auto_headers(self):
00075         # Some headers are added automatically, but should not be added by
00076         # .request() if they are explicitly set.
00077 
00078         class HeaderCountingBuffer(list):
00079             def __init__(self):
00080                 self.count = {}
00081             def append(self, item):
00082                 kv = item.split(b':')
00083                 if len(kv) > 1:
00084                     # item is a 'Key: Value' header string
00085                     lcKey = kv[0].decode('ascii').lower()
00086                     self.count.setdefault(lcKey, 0)
00087                     self.count[lcKey] += 1
00088                 list.append(self, item)
00089 
00090         for explicit_header in True, False:
00091             for header in 'Content-length', 'Host', 'Accept-encoding':
00092                 conn = client.HTTPConnection('example.com')
00093                 conn.sock = FakeSocket('blahblahblah')
00094                 conn._buffer = HeaderCountingBuffer()
00095 
00096                 body = 'spamspamspam'
00097                 headers = {}
00098                 if explicit_header:
00099                     headers[header] = str(len(body))
00100                 conn.request('POST', '/', body, headers)
00101                 self.assertEqual(conn._buffer.count[header.lower()], 1)

Here is the call graph for this function:

Definition at line 109 of file test_httplib.py.

00109 
00110     def test_ipv6host_header(self):
00111         # Default host header on IPv6 transaction should wrapped by [] if
00112         # its actual IPv6 address
00113         expected = b'GET /foo HTTP/1.1\r\nHost: [2001::]:81\r\n' \
00114                    b'Accept-Encoding: identity\r\n\r\n'
00115         conn = client.HTTPConnection('[2001::]:81')
00116         sock = FakeSocket('')
00117         conn.sock = sock
00118         conn.request('GET', '/foo')
00119         self.assertTrue(sock.data.startswith(expected))
00120 
00121         expected = b'GET /foo HTTP/1.1\r\nHost: [2001:102A::]\r\n' \
00122                    b'Accept-Encoding: identity\r\n\r\n'
00123         conn = client.HTTPConnection('[2001:102A::]')
00124         sock = FakeSocket('')
00125         conn.sock = sock
00126         conn.request('GET', '/foo')
00127         self.assertTrue(sock.data.startswith(expected))
00128 

Here is the call graph for this function:

Definition at line 102 of file test_httplib.py.

00102 
00103     def test_putheader(self):
00104         conn = client.HTTPConnection('example.com')
00105         conn.sock = FakeSocket(None)
00106         conn.putrequest('GET','/')
00107         conn.putheader('Content-length', 42)
00108         self.assertTrue(b'Content-length: 42' in conn._buffer)

Here is the call graph for this function:


Member Data Documentation

Definition at line 79 of file test_httplib.py.


The documentation for this class was generated from the following file: