summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_httplib.py
diff options
context:
space:
mode:
authorR David Murray <rdmurray@bitdance.com>2016-09-07 21:46:55 (GMT)
committerR David Murray <rdmurray@bitdance.com>2016-09-07 21:46:55 (GMT)
commit1badd2816361354f5e69d234b4ff3315f5f590cc (patch)
treebecb75e793dfd3ea3e0b49865a34023768b4ba0d /Lib/test/test_httplib.py
parentd0600ed524acb8b05b78d7399e8de136090703a0 (diff)
parentdc1650ca062a99d41a029a6645dc72fd7d820c94 (diff)
downloadcpython-1badd2816361354f5e69d234b4ff3315f5f590cc.zip
cpython-1badd2816361354f5e69d234b4ff3315f5f590cc.tar.gz
cpython-1badd2816361354f5e69d234b4ff3315f5f590cc.tar.bz2
Merge: #22233: Only split headers on \r and/or \n, per email RFCs.
Diffstat (limited to 'Lib/test/test_httplib.py')
-rw-r--r--Lib/test/test_httplib.py30
1 files changed, 30 insertions, 0 deletions
diff --git a/Lib/test/test_httplib.py b/Lib/test/test_httplib.py
index 359e0bb..3fc02ea 100644
--- a/Lib/test/test_httplib.py
+++ b/Lib/test/test_httplib.py
@@ -283,6 +283,36 @@ class HeaderTests(TestCase):
self.assertEqual(resp.getheader('First'), 'val')
self.assertEqual(resp.getheader('Second'), 'val')
+ def test_parse_all_octets(self):
+ # Ensure no valid header field octet breaks the parser
+ body = (
+ b'HTTP/1.1 200 OK\r\n'
+ b"!#$%&'*+-.^_`|~: value\r\n" # Special token characters
+ b'VCHAR: ' + bytes(range(0x21, 0x7E + 1)) + b'\r\n'
+ b'obs-text: ' + bytes(range(0x80, 0xFF + 1)) + b'\r\n'
+ b'obs-fold: text\r\n'
+ b' folded with space\r\n'
+ b'\tfolded with tab\r\n'
+ b'Content-Length: 0\r\n'
+ b'\r\n'
+ )
+ sock = FakeSocket(body)
+ resp = client.HTTPResponse(sock)
+ resp.begin()
+ self.assertEqual(resp.getheader('Content-Length'), '0')
+ self.assertEqual(resp.msg['Content-Length'], '0')
+ self.assertEqual(resp.getheader("!#$%&'*+-.^_`|~"), 'value')
+ self.assertEqual(resp.msg["!#$%&'*+-.^_`|~"], 'value')
+ vchar = ''.join(map(chr, range(0x21, 0x7E + 1)))
+ self.assertEqual(resp.getheader('VCHAR'), vchar)
+ self.assertEqual(resp.msg['VCHAR'], vchar)
+ self.assertIsNotNone(resp.getheader('obs-text'))
+ self.assertIn('obs-text', resp.msg)
+ for folded in (resp.getheader('obs-fold'), resp.msg['obs-fold']):
+ self.assertTrue(folded.startswith('text'))
+ self.assertIn(' folded with space', folded)
+ self.assertTrue(folded.endswith('folded with tab'))
+
def test_invalid_headers(self):
conn = client.HTTPConnection('example.com')
conn.sock = FakeSocket('')