diff options
author | Facundo Batista <facundobatista@gmail.com> | 2008-08-16 14:44:32 (GMT) |
---|---|---|
committer | Facundo Batista <facundobatista@gmail.com> | 2008-08-16 14:44:32 (GMT) |
commit | 72dc1eadd918dc9ddd6a30149d90617d706a0b19 (patch) | |
tree | 39152c04863345c7f9f20c4326570ae3c01a0e50 /Lib/test/test_urllib2.py | |
parent | 371bb50b87e0450bf4bcf06ac89a47a417bf908f (diff) | |
download | cpython-72dc1eadd918dc9ddd6a30149d90617d706a0b19.zip cpython-72dc1eadd918dc9ddd6a30149d90617d706a0b19.tar.gz cpython-72dc1eadd918dc9ddd6a30149d90617d706a0b19.tar.bz2 |
Issue #2776: fixed small issue when handling an URL with double slash
after a 302 response in the case of not going through a proxy.
Diffstat (limited to 'Lib/test/test_urllib2.py')
-rw-r--r-- | Lib/test/test_urllib2.py | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/Lib/test/test_urllib2.py b/Lib/test/test_urllib2.py index 30aa8f2..0ab6367 100644 --- a/Lib/test/test_urllib2.py +++ b/Lib/test/test_urllib2.py @@ -770,6 +770,34 @@ class HandlerTests(unittest.TestCase): self.assertEqual(req.unredirected_hdrs["Host"], "baz") self.assertEqual(req.unredirected_hdrs["Spam"], "foo") + def test_http_doubleslash(self): + # Checks the presence of any unnecessary double slash in url does not + # break anything. Previously, a double slash directly after the host + # could could cause incorrect parsing. + h = urllib.request.AbstractHTTPHandler() + o = h.parent = MockOpener() + + data = "" + ds_urls = [ + "http://example.com/foo/bar/baz.html", + "http://example.com//foo/bar/baz.html", + "http://example.com/foo//bar/baz.html", + "http://example.com/foo/bar//baz.html" + ] + + for ds_url in ds_urls: + ds_req = Request(ds_url, data) + + # Check whether host is determined correctly if there is no proxy + np_ds_req = h.do_request_(ds_req) + self.assertEqual(np_ds_req.unredirected_hdrs["Host"],"example.com") + + # Check whether host is determined correctly if there is a proxy + ds_req.set_proxy("someproxy:3128",None) + p_ds_req = h.do_request_(ds_req) + self.assertEqual(p_ds_req.unredirected_hdrs["Host"],"example.com") + + def test_errors(self): h = urllib.request.HTTPErrorProcessor() o = h.parent = MockOpener() |