diff options
author | Martin Panter <vadmium+py@gmail.com> | 2016-05-16 01:07:13 (GMT) |
---|---|---|
committer | Martin Panter <vadmium+py@gmail.com> | 2016-05-16 01:07:13 (GMT) |
commit | ce6e06874b235f7825888c20fd2c6f4670a4aeba (patch) | |
tree | cbab88edff943bca30d70f2ec8622616636c01ba /Lib/test/test_urllib2.py | |
parent | f95455da4c3c61a302d62322a4bcb17a629efd4b (diff) | |
download | cpython-ce6e06874b235f7825888c20fd2c6f4670a4aeba.zip cpython-ce6e06874b235f7825888c20fd2c6f4670a4aeba.tar.gz cpython-ce6e06874b235f7825888c20fd2c6f4670a4aeba.tar.bz2 |
Issue #14132: Fix redirect handling when target is just a query string
Diffstat (limited to 'Lib/test/test_urllib2.py')
-rw-r--r-- | Lib/test/test_urllib2.py | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/Lib/test/test_urllib2.py b/Lib/test/test_urllib2.py index b5bba55..58c3071 100644 --- a/Lib/test/test_urllib2.py +++ b/Lib/test/test_urllib2.py @@ -462,7 +462,7 @@ class MockHTTPHandler(urllib.request.BaseHandler): self.requests = [] def http_open(self, req): - import email, http.client, copy + import email, copy self.requests.append(copy.deepcopy(req)) if self._count == 0: self._count = self._count + 1 @@ -1208,6 +1208,22 @@ class HandlerTests(unittest.TestCase): fp = o.open('http://www.example.com') self.assertEqual(fp.geturl(), redirected_url.strip()) + def test_redirect_no_path(self): + # Issue 14132: Relative redirect strips original path + real_class = http.client.HTTPConnection + response1 = b"HTTP/1.1 302 Found\r\nLocation: ?query\r\n\r\n" + http.client.HTTPConnection = test_urllib.fakehttp(response1) + self.addCleanup(setattr, http.client, "HTTPConnection", real_class) + urls = iter(("/path", "/path?query")) + def request(conn, method, url, *pos, **kw): + self.assertEqual(url, next(urls)) + real_class.request(conn, method, url, *pos, **kw) + # Change response for subsequent connection + conn.__class__.fakedata = b"HTTP/1.1 200 OK\r\n\r\nHello!" + http.client.HTTPConnection.request = request + fp = urllib.request.urlopen("http://python.org/path") + self.assertEqual(fp.geturl(), "http://python.org/path?query") + def test_proxy(self): o = OpenerDirector() ph = urllib.request.ProxyHandler(dict(http="proxy.example.com:3128")) |