diff options
author | R David Murray <rdmurray@bitdance.com> | 2013-03-20 04:10:51 (GMT) |
---|---|---|
committer | R David Murray <rdmurray@bitdance.com> | 2013-03-20 04:10:51 (GMT) |
commit | 9cc7d455718456dd88daf829c29bec9527530b11 (patch) | |
tree | cd69e5d356ffef3ae5ab61bcf50b6e4d75f9f3bf /Lib | |
parent | d5a6e25470bb4f40c5bdd586641d7a4fce5fb64a (diff) | |
download | cpython-9cc7d455718456dd88daf829c29bec9527530b11.zip cpython-9cc7d455718456dd88daf829c29bec9527530b11.tar.gz cpython-9cc7d455718456dd88daf829c29bec9527530b11.tar.bz2 |
#17485: Delete the Content-Length header if the data attribute is deleted.
This is a follow on to issue 16464. Original patch by Daniel Wozniak.
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/test/test_urllib2.py | 13 | ||||
-rw-r--r-- | Lib/urllib/request.py | 2 |
2 files changed, 12 insertions, 3 deletions
diff --git a/Lib/test/test_urllib2.py b/Lib/test/test_urllib2.py index 3e19ecf..0e05723 100644 --- a/Lib/test/test_urllib2.py +++ b/Lib/test/test_urllib2.py @@ -1488,11 +1488,20 @@ class RequestTests(unittest.TestCase): # if we change data we need to remove content-length header # (cause it's most probably calculated for previous value) def test_setting_data_should_remove_content_length(self): - self.assertFalse("Content-length" in self.get.unredirected_hdrs) + self.assertNotIn("Content-length", self.get.unredirected_hdrs) self.get.add_unredirected_header("Content-length", 42) self.assertEqual(42, self.get.unredirected_hdrs["Content-length"]) self.get.data = "spam" - self.assertFalse("Content-length" in self.get.unredirected_hdrs) + self.assertNotIn("Content-length", self.get.unredirected_hdrs) + + # issue 17485 same for deleting data. + def test_deleting_data_should_remove_content_length(self): + self.assertNotIn("Content-length", self.get.unredirected_hdrs) + self.get.data = 'foo' + self.get.add_unredirected_header("Content-length", 3) + self.assertEqual(3, self.get.unredirected_hdrs["Content-length"]) + del self.get.data + self.assertNotIn("Content-length", self.get.unredirected_hdrs) def test_get_full_url(self): self.assertEqual("http://www.python.org/~jeremy/", diff --git a/Lib/urllib/request.py b/Lib/urllib/request.py index 90731cb..8b3cdf9 100644 --- a/Lib/urllib/request.py +++ b/Lib/urllib/request.py @@ -296,7 +296,7 @@ class Request: @data.deleter def data(self): - self._data = None + self.data = None def _parse(self): self.type, rest = splittype(self.full_url) |