summaryrefslogtreecommitdiff
path: root/Lib/test/test_httplib.py
diff options
context:
space:
mode:
authorJason R. Coombs <jaraco@jaraco.com>2019-09-28 12:44:12 -0400
committerNed Deily <nad@python.org>2019-09-28 12:44:12 -0400
commit5b18ce60b432d1dfa6f6988be07dd55646201a9b (patch)
treef19711f9a8428898894bfea84bc7c5a526bb7128 /Lib/test/test_httplib.py
parent1698cacfb924d1df452e78d11a4bf81ae7777389 (diff)
downloadcpython-git-5b18ce60b432d1dfa6f6988be07dd55646201a9b.tar.gz
[3.6] bpo-38216, bpo-36274: Allow subclasses to separately override validation and encoding behavior (GH-16448) (GH-16462)
(cherry picked from commit 7774d7831e8809795c64ce27f7df52674581d298) Co-authored-by: Jason R. Coombs <jaraco@jaraco.com>
Diffstat (limited to 'Lib/test/test_httplib.py')
-rw-r--r--Lib/test/test_httplib.py29
1 files changed, 29 insertions, 0 deletions
diff --git a/Lib/test/test_httplib.py b/Lib/test/test_httplib.py
index 714d521cf0..14d42d4837 100644
--- a/Lib/test/test_httplib.py
+++ b/Lib/test/test_httplib.py
@@ -1132,6 +1132,34 @@ class BasicTest(TestCase):
thread.join()
self.assertEqual(result, b"proxied data\n")
+ def test_putrequest_override_validation(self):
+ """
+ It should be possible to override the default validation
+ behavior in putrequest (bpo-38216).
+ """
+ class UnsafeHTTPConnection(client.HTTPConnection):
+ def _validate_path(self, url):
+ pass
+
+ conn = UnsafeHTTPConnection('example.com')
+ conn.sock = FakeSocket('')
+ conn.putrequest('GET', '/\x00')
+
+ def test_putrequest_override_encoding(self):
+ """
+ It should be possible to override the default encoding
+ to transmit bytes in another encoding even if invalid
+ (bpo-36274).
+ """
+ class UnsafeHTTPConnection(client.HTTPConnection):
+ def _encode_request(self, str_url):
+ return str_url.encode('utf-8')
+
+ conn = UnsafeHTTPConnection('example.com')
+ conn.sock = FakeSocket('')
+ conn.putrequest('GET', '/☃')
+
+
class ExtendedReadTest(TestCase):
"""
Test peek(), read1(), readline()
@@ -1256,6 +1284,7 @@ class ExtendedReadTest(TestCase):
p = self.resp.peek(0)
self.assertLessEqual(0, len(p))
+
class ExtendedReadTestChunked(ExtendedReadTest):
"""
Test peek(), read1(), readline() in chunked mode