(self)
| 310 | self.assertEqual(resp.getheader('Second'), 'val') |
| 311 | |
| 312 | def test_parse_all_octets(self): |
| 313 | # Ensure no valid header field octet breaks the parser |
| 314 | body = ( |
| 315 | b'HTTP/1.1 200 OK\r\n' |
| 316 | b"!#$%&'*+-.^_`|~: value\r\n" # Special token characters |
| 317 | b'VCHAR: ' + bytes(range(0x21, 0x7E + 1)) + b'\r\n' |
| 318 | b'obs-text: ' + bytes(range(0x80, 0xFF + 1)) + b'\r\n' |
| 319 | b'obs-fold: text\r\n' |
| 320 | b' folded with space\r\n' |
| 321 | b'\tfolded with tab\r\n' |
| 322 | b'Content-Length: 0\r\n' |
| 323 | b'\r\n' |
| 324 | ) |
| 325 | sock = FakeSocket(body) |
| 326 | resp = client.HTTPResponse(sock) |
| 327 | resp.begin() |
| 328 | self.assertEqual(resp.getheader('Content-Length'), '0') |
| 329 | self.assertEqual(resp.msg['Content-Length'], '0') |
| 330 | self.assertEqual(resp.getheader("!#$%&'*+-.^_`|~"), 'value') |
| 331 | self.assertEqual(resp.msg["!#$%&'*+-.^_`|~"], 'value') |
| 332 | vchar = ''.join(map(chr, range(0x21, 0x7E + 1))) |
| 333 | self.assertEqual(resp.getheader('VCHAR'), vchar) |
| 334 | self.assertEqual(resp.msg['VCHAR'], vchar) |
| 335 | self.assertIsNotNone(resp.getheader('obs-text')) |
| 336 | self.assertIn('obs-text', resp.msg) |
| 337 | for folded in (resp.getheader('obs-fold'), resp.msg['obs-fold']): |
| 338 | self.assertStartsWith(folded, 'text') |
| 339 | self.assertIn(' folded with space', folded) |
| 340 | self.assertEndsWith(folded, 'folded with tab') |
| 341 | |
| 342 | def test_invalid_headers(self): |
| 343 | conn = client.HTTPConnection('example.com') |
nothing calls this directly
no test coverage detected