MCPcopy Index your code
hub / github.com/RustPython/RustPython / test_explicit_headers

Method test_explicit_headers

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

Source from the content-addressed store, hash-verified

423 self.assertEqual(body, self.expected_body)
424
425 def test_explicit_headers(self):
426 # explicit chunked
427 conn = client.HTTPConnection('example.com')
428 conn.sock = FakeSocket(b'')
429 # this shouldn't actually be automatically chunk-encoded because the
430 # calling code has explicitly stated that it's taking care of it
431 conn.request(
432 'POST', '/', self._make_body(), {'Transfer-Encoding': 'chunked'})
433
434 _, headers, body = self._parse_request(conn.sock.data)
435 self.assertNotIn('content-length', [k.lower() for k in headers.keys()])
436 self.assertEqual(headers['Transfer-Encoding'], 'chunked')
437 self.assertEqual(body, self.expected_body)
438
439 # explicit chunked, string body
440 conn = client.HTTPConnection('example.com')
441 conn.sock = FakeSocket(b'')
442 conn.request(
443 'POST', '/', self.expected_body.decode('latin-1'),
444 {'Transfer-Encoding': 'chunked'})
445
446 _, headers, body = self._parse_request(conn.sock.data)
447 self.assertNotIn('content-length', [k.lower() for k in headers.keys()])
448 self.assertEqual(headers['Transfer-Encoding'], 'chunked')
449 self.assertEqual(body, self.expected_body)
450
451 # User-specified TE, but request() does the chunk encoding
452 conn = client.HTTPConnection('example.com')
453 conn.sock = FakeSocket(b'')
454 conn.request('POST', '/',
455 headers={'Transfer-Encoding': 'gzip, chunked'},
456 encode_chunked=True,
457 body=self._make_body())
458 _, headers, body = self._parse_request(conn.sock.data)
459 self.assertNotIn('content-length', [k.lower() for k in headers])
460 self.assertEqual(headers['Transfer-Encoding'], 'gzip, chunked')
461 self.assertEqual(self._parse_chunked(body), self.expected_body)
462
463 def test_request(self):
464 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