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

Method test_explicit_headers

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

Source from the content-addressed store, hash-verified

469 self.assertEqual(body, self.expected_body)
470
471 def test_explicit_headers(self):
472 # explicit chunked
473 conn = client.HTTPConnection('example.com')
474 conn.sock = FakeSocket(b'')
475 # this shouldn't actually be automatically chunk-encoded because the
476 # calling code has explicitly stated that it's taking care of it
477 conn.request(
478 'POST', '/', self._make_body(), {'Transfer-Encoding': 'chunked'})
479
480 _, headers, body = self._parse_request(conn.sock.data)
481 self.assertNotIn('content-length', [k.lower() for k in headers.keys()])
482 self.assertEqual(headers['Transfer-Encoding'], 'chunked')
483 self.assertEqual(body, self.expected_body)
484
485 # explicit chunked, string body
486 conn = client.HTTPConnection('example.com')
487 conn.sock = FakeSocket(b'')
488 conn.request(
489 'POST', '/', self.expected_body.decode('latin-1'),
490 {'Transfer-Encoding': 'chunked'})
491
492 _, headers, body = self._parse_request(conn.sock.data)
493 self.assertNotIn('content-length', [k.lower() for k in headers.keys()])
494 self.assertEqual(headers['Transfer-Encoding'], 'chunked')
495 self.assertEqual(body, self.expected_body)
496
497 # User-specified TE, but request() does the chunk encoding
498 conn = client.HTTPConnection('example.com')
499 conn.sock = FakeSocket(b'')
500 conn.request('POST', '/',
501 headers={'Transfer-Encoding': 'gzip, chunked'},
502 encode_chunked=True,
503 body=self._make_body())
504 _, headers, body = self._parse_request(conn.sock.data)
505 self.assertNotIn('content-length', [k.lower() for k in headers])
506 self.assertEqual(headers['Transfer-Encoding'], 'gzip, chunked')
507 self.assertEqual(self._parse_chunked(body), self.expected_body)
508
509 def test_request(self):
510 for empty_lines in (False, True,):

Callers

nothing calls this directly

Calls 10

requestMethod · 0.95
_make_bodyMethod · 0.95
_parse_requestMethod · 0.95
_parse_chunkedMethod · 0.95
assertNotInMethod · 0.80
FakeSocketClass · 0.70
lowerMethod · 0.45
keysMethod · 0.45
assertEqualMethod · 0.45
decodeMethod · 0.45

Tested by

no test coverage detected