MCPcopy Index your code
hub / github.com/python/cpython / test_auto_headers

Method test_auto_headers

Lib/test/test_httplib.py:138–165  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

136
137class HeaderTests(TestCase):
138 def test_auto_headers(self):
139 # Some headers are added automatically, but should not be added by
140 # .request() if they are explicitly set.
141
142 class HeaderCountingBuffer(list):
143 def __init__(self):
144 self.count = {}
145 def append(self, item):
146 kv = item.split(b':')
147 if len(kv) > 1:
148 # item is a 'Key: Value' header string
149 lcKey = kv[0].decode('ascii').lower()
150 self.count.setdefault(lcKey, 0)
151 self.count[lcKey] += 1
152 list.append(self, item)
153
154 for explicit_header in True, False:
155 for header in 'Content-length', 'Host', 'Accept-encoding':
156 conn = client.HTTPConnection('example.com')
157 conn.sock = FakeSocket('blahblahblah')
158 conn._buffer = HeaderCountingBuffer()
159
160 body = 'spamspamspam'
161 headers = {}
162 if explicit_header:
163 headers[header] = str(len(body))
164 conn.request('POST', '/', body, headers)
165 self.assertEqual(conn._buffer.count[header.lower()], 1)
166
167 def test_content_length_0(self):
168

Callers

nothing calls this directly

Calls 6

requestMethod · 0.95
strFunction · 0.85
FakeSocketClass · 0.70
assertEqualMethod · 0.45
lowerMethod · 0.45

Tested by

no test coverage detected