summaryrefslogtreecommitdiff
path: root/Lib/test/test_httplib.py
diff options
context:
space:
mode:
authorR David Murray <rdmurray@bitdance.com>2016-09-07 17:44:34 -0400
committerR David Murray <rdmurray@bitdance.com>2016-09-07 17:44:34 -0400
commitdc1650ca062a99d41a029a6645dc72fd7d820c94 (patch)
tree7719487f2ea0d6a95d2e024e365dbedacf697534 /Lib/test/test_httplib.py
parent6b46ec7733ad7391b9e008d2b273c556f140f88e (diff)
downloadcpython-git-dc1650ca062a99d41a029a6645dc72fd7d820c94.tar.gz
#22233: Only split headers on \r and/or \n, per email RFCs.
Original patch by Martin Panter, new policy fixes by me.
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 f45e352d6a..155ab0f19b 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('')