@@ -359,7 +359,7 @@ def test_broken_chunked_encoding(self):
359359 sorted (headers .keys ()),
360360 ["connection" , "content-length" , "content-type" , "date" , "server" ],
361361 )
362- self .assertEqual (headers ["content-type" ], "text/plain" )
362+ self .assertEqual (headers ["content-type" ], "text/plain; charset=utf-8 " )
363363 # connection has been closed
364364 self .send_check_error (to_send )
365365 self .assertRaises (ConnectionClosed , read_http , fp )
@@ -381,7 +381,7 @@ def test_broken_chunked_encoding_invalid_hex(self):
381381 sorted (headers .keys ()),
382382 ["connection" , "content-length" , "content-type" , "date" , "server" ],
383383 )
384- self .assertEqual (headers ["content-type" ], "text/plain" )
384+ self .assertEqual (headers ["content-type" ], "text/plain; charset=utf-8 " )
385385 # connection has been closed
386386 self .send_check_error (to_send )
387387 self .assertRaises (ConnectionClosed , read_http , fp )
@@ -403,7 +403,7 @@ def test_broken_chunked_encoding_invalid_extension(self):
403403 sorted (headers .keys ()),
404404 ["connection" , "content-length" , "content-type" , "date" , "server" ],
405405 )
406- self .assertEqual (headers ["content-type" ], "text/plain" )
406+ self .assertEqual (headers ["content-type" ], "text/plain; charset=utf-8 " )
407407 # connection has been closed
408408 self .send_check_error (to_send )
409409 self .assertRaises (ConnectionClosed , read_http , fp )
@@ -428,7 +428,7 @@ def test_broken_chunked_encoding_missing_chunk_end(self):
428428 sorted (headers .keys ()),
429429 ["connection" , "content-length" , "content-type" , "date" , "server" ],
430430 )
431- self .assertEqual (headers ["content-type" ], "text/plain" )
431+ self .assertEqual (headers ["content-type" ], "text/plain; charset=utf-8 " )
432432 # connection has been closed
433433 self .send_check_error (to_send )
434434 self .assertRaises (ConnectionClosed , read_http , fp )
@@ -1121,7 +1121,7 @@ def test_request_body_too_large_chunked_encoding(self):
11211121 self .assertline (line , "413" , "Request Entity Too Large" , "HTTP/1.1" )
11221122 cl = int (headers ["content-length" ])
11231123 self .assertEqual (cl , len (response_body ))
1124- self .assertEqual (headers ["content-type" ], "text/plain" )
1124+ self .assertEqual (headers ["content-type" ], "text/plain; charset=utf-8 " )
11251125 # connection has been closed
11261126 self .send_check_error (to_send )
11271127 self .assertRaises (ConnectionClosed , read_http , fp )
@@ -1269,6 +1269,49 @@ def test_in_generator(self):
12691269 self .assertRaises (ConnectionClosed , read_http , fp )
12701270
12711271
1272+ class InternalServerErrorTestsWithTraceback :
1273+ def setUp (self ):
1274+ from tests .fixtureapps import error_traceback
1275+
1276+ self .start_subprocess (error_traceback .app , expose_tracebacks = True )
1277+
1278+ def tearDown (self ):
1279+ self .stop_subprocess ()
1280+
1281+ def test_expose_tracebacks_http_10 (self ):
1282+ to_send = b"GET / HTTP/1.0\r \n \r \n "
1283+ self .connect ()
1284+ self .sock .send (to_send )
1285+ with self .sock .makefile ("rb" , 0 ) as fp :
1286+ line , headers , response_body = read_http (fp )
1287+ self .assertline (line , "500" , "Internal Server Error" , "HTTP/1.0" )
1288+ cl = int (headers ["content-length" ])
1289+ self .assertEqual (cl , len (response_body ))
1290+ self .assertTrue (response_body .startswith (b"Internal Server Error" ))
1291+ self .assertEqual (headers ["connection" ], "close" )
1292+ # connection has been closed
1293+ self .send_check_error (to_send )
1294+ self .assertRaises (ConnectionClosed , read_http , fp )
1295+
1296+ def test_expose_tracebacks_http_11 (self ):
1297+ to_send = b"GET / HTTP/1.1\r \n \r \n "
1298+ self .connect ()
1299+ self .sock .send (to_send )
1300+ with self .sock .makefile ("rb" , 0 ) as fp :
1301+ line , headers , response_body = read_http (fp )
1302+ self .assertline (line , "500" , "Internal Server Error" , "HTTP/1.1" )
1303+ cl = int (headers ["content-length" ])
1304+ self .assertEqual (cl , len (response_body ))
1305+ self .assertTrue (response_body .startswith (b"Internal Server Error" ))
1306+ self .assertEqual (
1307+ sorted (headers .keys ()),
1308+ ["connection" , "content-length" , "content-type" , "date" , "server" ],
1309+ )
1310+ # connection has been closed
1311+ self .send_check_error (to_send )
1312+ self .assertRaises (ConnectionClosed , read_http , fp )
1313+
1314+
12721315class FileWrapperTests :
12731316 def setUp (self ):
12741317 from tests .fixtureapps import filewrapper
@@ -1538,6 +1581,12 @@ class TcpInternalServerErrorTests(
15381581 pass
15391582
15401583
1584+ class TcpInternalServerErrorTestsWithTraceback (
1585+ InternalServerErrorTestsWithTraceback , TcpTests , unittest .TestCase
1586+ ):
1587+ pass
1588+
1589+
15411590class TcpFileWrapperTests (FileWrapperTests , TcpTests , unittest .TestCase ):
15421591 pass
15431592
@@ -1604,6 +1653,11 @@ class UnixInternalServerErrorTests(
16041653 ):
16051654 pass
16061655
1656+ class UnixInternalServerErrorTestsWithTraceback (
1657+ InternalServerErrorTestsWithTraceback , UnixTests , unittest .TestCase
1658+ ):
1659+ pass
1660+
16071661 class UnixFileWrapperTests (FileWrapperTests , UnixTests , unittest .TestCase ):
16081662 pass
16091663
0 commit comments