(self)
| 981 | self.assertEqual(req.unredirected_hdrs["Spam"], "foo") |
| 982 | |
| 983 | def test_http_body_file(self): |
| 984 | # A regular file - chunked encoding is used unless Content Length is |
| 985 | # already set. |
| 986 | |
| 987 | h = urllib.request.AbstractHTTPHandler() |
| 988 | o = h.parent = MockOpener() |
| 989 | |
| 990 | file_obj = tempfile.NamedTemporaryFile(mode='w+b', delete=False) |
| 991 | file_path = file_obj.name |
| 992 | file_obj.close() |
| 993 | self.addCleanup(os.unlink, file_path) |
| 994 | |
| 995 | with open(file_path, "rb") as f: |
| 996 | req = Request("http://example.com/", f, {}) |
| 997 | newreq = h.do_request_(req) |
| 998 | te = newreq.get_header('Transfer-encoding') |
| 999 | self.assertEqual(te, "chunked") |
| 1000 | self.assertFalse(newreq.has_header('Content-length')) |
| 1001 | |
| 1002 | with open(file_path, "rb") as f: |
| 1003 | req = Request("http://example.com/", f, {"Content-Length": 30}) |
| 1004 | newreq = h.do_request_(req) |
| 1005 | self.assertEqual(int(newreq.get_header('Content-length')), 30) |
| 1006 | self.assertFalse(newreq.has_header("Transfer-encoding")) |
| 1007 | |
| 1008 | def test_http_body_fileobj(self): |
| 1009 | # A file object - chunked encoding is used |
nothing calls this directly
no test coverage detected