Test the connection is cleaned up when the response is closed
(self)
| 1820 | self.assertTrue(http_handler.has_auth_header) |
| 1821 | |
| 1822 | def test_http_closed(self): |
| 1823 | """Test the connection is cleaned up when the response is closed""" |
| 1824 | for (transfer, data) in ( |
| 1825 | ("Connection: close", b"data"), |
| 1826 | ("Transfer-Encoding: chunked", b"4\r\ndata\r\n0\r\n\r\n"), |
| 1827 | ("Content-Length: 4", b"data"), |
| 1828 | ): |
| 1829 | header = "HTTP/1.1 200 OK\r\n{}\r\n\r\n".format(transfer) |
| 1830 | conn = test_urllib.fakehttp(header.encode() + data) |
| 1831 | handler = urllib.request.AbstractHTTPHandler() |
| 1832 | req = Request("http://dummy/") |
| 1833 | req.timeout = None |
| 1834 | with handler.do_open(conn, req) as resp: |
| 1835 | resp.read() |
| 1836 | self.assertTrue(conn.fakesock.closed, |
| 1837 | "Connection not closed with {!r}".format(transfer)) |
| 1838 | |
| 1839 | def test_invalid_closed(self): |
| 1840 | """Test the connection is cleaned up after an invalid response""" |