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

Method test_parse_all_octets

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

Source from the content-addressed store, hash-verified

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')

Callers

nothing calls this directly

Calls 9

beginMethod · 0.95
getheaderMethod · 0.95
assertIsNotNoneMethod · 0.80
assertInMethod · 0.80
assertStartsWithMethod · 0.80
assertEndsWithMethod · 0.80
FakeSocketClass · 0.70
assertEqualMethod · 0.45
joinMethod · 0.45

Tested by

no test coverage detected