(self)
| 136 | |
| 137 | class 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 |
nothing calls this directly
no test coverage detected