Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 5ef4fc2

Browse files
csabellarhettinger
authored andcommitted
bpo-35565: Add detail to assertion failure message in wsgiref (GH-11293)
1 parent 32d96a2 commit 5ef4fc2

2 files changed

Lines changed: 15 additions & 1 deletion

File tree

Lib/test/test_wsgiref.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,19 @@ def bad_app(environ, start_response):
193193
))
194194
self.assertEqual(err.splitlines()[-2], exc_message)
195195

196+
@unittest.skipIf(support.python_is_optimized(),
197+
"Python was compiled with optimizations")
198+
def test_hop_by_hop_validation_error(self):
199+
def bad_app(environ, start_response):
200+
start_response("200 OK", [('Content-Type', 'text/plain'),
201+
('Connection', 'close')])
202+
return ["Hello, world!"]
203+
out, err = run_amock(bad_app)
204+
self.assertTrue(out.endswith(
205+
b"A server error occurred. Please contact the administrator."
206+
))
207+
self.assertRaises(AssertionError)
208+
196209
def test_wsgi_input(self):
197210
def bad_app(e,s):
198211
e["wsgi.input"].read()

Lib/wsgiref/handlers.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,8 @@ def start_response(self, status, headers,exc_info=None):
233233
for name, val in headers:
234234
name = self._convert_string_type(name, "Header name")
235235
val = self._convert_string_type(val, "Header value")
236-
assert not is_hop_by_hop(name),"Hop-by-hop headers not allowed"
236+
assert not is_hop_by_hop(name),\
237+
f"Hop-by-hop header, '{name}: {val}', not allowed"
237238

238239
return self.write
239240

0 commit comments

Comments
 (0)