summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorMartin Panter <vadmium+py@gmail.com>2016-04-03 01:28:49 (GMT)
committerMartin Panter <vadmium+py@gmail.com>2016-04-03 01:28:49 (GMT)
commitb93e4b2480281ea17ec2b2ef8cbb42a94bf95066 (patch)
treebb39e62153cee42d8ba16bbef5787e7dec88328c /Lib
parent1862bb27698987d2b38f81c0e9459df4bf897139 (diff)
parentacc03195b0609490a4e5f8b1d9eb504c22c6526e (diff)
downloadcpython-b93e4b2480281ea17ec2b2ef8cbb42a94bf95066.zip
cpython-b93e4b2480281ea17ec2b2ef8cbb42a94bf95066.tar.gz
cpython-b93e4b2480281ea17ec2b2ef8cbb42a94bf95066.tar.bz2
Issue #26586: Merge excessive HTTP header handling from 3.5
Diffstat (limited to 'Lib')
-rw-r--r--Lib/http/server.py7
-rw-r--r--Lib/test/test_httpservers.py7
2 files changed, 14 insertions, 0 deletions
diff --git a/Lib/http/server.py b/Lib/http/server.py
index 5e91826..de6b531 100644
--- a/Lib/http/server.py
+++ b/Lib/http/server.py
@@ -338,6 +338,13 @@ class BaseHTTPRequestHandler(socketserver.StreamRequestHandler):
HTTPStatus.BAD_REQUEST,
"Line too long")
return False
+ except http.client.HTTPException as err:
+ self.send_error(
+ HTTPStatus.REQUEST_HEADER_FIELDS_TOO_LARGE,
+ "Too many headers",
+ str(err)
+ )
+ return False
conntype = self.headers.get('Connection', "")
if conntype.lower() == 'close':
diff --git a/Lib/test/test_httpservers.py b/Lib/test/test_httpservers.py
index 5d44825..98798ae 100644
--- a/Lib/test/test_httpservers.py
+++ b/Lib/test/test_httpservers.py
@@ -859,6 +859,13 @@ class BaseHTTPRequestHandlerTestCase(unittest.TestCase):
self.assertFalse(self.handler.get_called)
self.assertEqual(self.handler.requestline, 'GET / HTTP/1.1')
+ def test_too_many_headers(self):
+ result = self.send_typical_request(
+ b'GET / HTTP/1.1\r\n' + b'X-Foo: bar\r\n' * 101 + b'\r\n')
+ self.assertEqual(result[0], b'HTTP/1.1 431 Too many headers\r\n')
+ self.assertFalse(self.handler.get_called)
+ self.assertEqual(self.handler.requestline, 'GET / HTTP/1.1')
+
def test_close_connection(self):
# handle_one_request() should be repeatedly called until
# it sets close_connection