summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Lib/test/test_wsgiref.py13
-rw-r--r--Lib/wsgiref/handlers.py3
2 files changed, 15 insertions, 1 deletions
diff --git a/Lib/test/test_wsgiref.py b/Lib/test/test_wsgiref.py
index 737dfed..3a953d8 100644
--- a/Lib/test/test_wsgiref.py
+++ b/Lib/test/test_wsgiref.py
@@ -193,6 +193,19 @@ class IntegrationTests(TestCase):
))
self.assertEqual(err.splitlines()[-2], exc_message)
+ @unittest.skipIf(support.python_is_optimized(),
+ "Python was compiled with optimizations")
+ def test_hop_by_hop_validation_error(self):
+ def bad_app(environ, start_response):
+ start_response("200 OK", [('Content-Type', 'text/plain'),
+ ('Connection', 'close')])
+ return ["Hello, world!"]
+ out, err = run_amock(bad_app)
+ self.assertTrue(out.endswith(
+ b"A server error occurred. Please contact the administrator."
+ ))
+ self.assertRaises(AssertionError)
+
def test_wsgi_input(self):
def bad_app(e,s):
e["wsgi.input"].read()
diff --git a/Lib/wsgiref/handlers.py b/Lib/wsgiref/handlers.py
index f4300b8..28ed9b7 100644
--- a/Lib/wsgiref/handlers.py
+++ b/Lib/wsgiref/handlers.py
@@ -233,7 +233,8 @@ class BaseHandler:
for name, val in headers:
name = self._convert_string_type(name, "Header name")
val = self._convert_string_type(val, "Header value")
- assert not is_hop_by_hop(name),"Hop-by-hop headers not allowed"
+ assert not is_hop_by_hop(name),\
+ f"Hop-by-hop header, '{name}: {val}', not allowed"
return self.write