comparison roundup/scripts/roundup_server.py @ 7112:c0d030bd472e

Fix: Send Content-Length header to client from top Exception handler The top exception handler in run_cgi wasn't sending the Content-Length header for the error message. This resulted in a hung client. Probably wasn't an issue with http 1.0, but when using 1.1 it's required.
author John Rouillard <rouilj@ieee.org>
date Sun, 11 Dec 2022 18:47:24 -0500
parents 8e4028669d2a
children 46f92ac4e170
comparison
equal deleted inserted replaced
7111:a7853002495c 7112:c0d030bd472e
270 except Exception: 270 except Exception:
271 exc, val, tb = sys.exc_info() 271 exc, val, tb = sys.exc_info()
272 if hasattr(socket, 'timeout') and isinstance(val, socket.timeout): 272 if hasattr(socket, 'timeout') and isinstance(val, socket.timeout):
273 self.log_error('timeout') 273 self.log_error('timeout')
274 else: 274 else:
275 # it'd be nice to be able to detect if these are going to have
276 # any effect...
277 self.send_response(400) 275 self.send_response(400)
278 self.send_header('Content-Type', 'text/html') 276 self.send_header('Content-Type', 'text/html')
279 self.end_headers()
280 if self.DEBUG_MODE: 277 if self.DEBUG_MODE:
281 try: 278 try:
282 reload(cgitb) 279 reload(cgitb)
283 self.wfile.write(s2b(cgitb.breaker())) 280 output = s2b(cgitb.breaker()) + s2b(cgitb.html())
284 self.wfile.write(s2b(cgitb.html()))
285 except Exception: 281 except Exception:
286 s = StringIO() 282 s = StringIO()
287 traceback.print_exc(None, s) 283 traceback.print_exc(None, s)
288 self.wfile.write(b"<pre>") 284 output = b"<pre>%s</pre>" % s2b(
289 self.wfile.write(s2b(html_escape(s.getvalue()))) 285 html_escape(s.getvalue()))
290 self.wfile.write(b"</pre>\n")
291 else: 286 else:
292 # user feedback 287 # user feedback
293 self.wfile.write(s2b(cgitb.breaker()))
294 ts = time.ctime() 288 ts = time.ctime()
295 self.wfile.write(s2b('''<p>%s: An error occurred. Please check 289 output = (
296 the server log for more information.</p>''' % ts)) 290 s2b('''<body><p>%s: An error occurred. Please check
291 the server log for more information.</p></body>''' %
292 ts)
293 )
297 # out to the logfile 294 # out to the logfile
298 print('EXCEPTION AT', ts) 295 print('EXCEPTION AT', ts)
299 traceback.print_exc() 296 traceback.print_exc()
297
298 # complete output to user.
299 self.send_header('Content-Length', len(output))
300 self.end_headers()
301 self.wfile.write(output)
300 302
301 do_GET = do_POST = do_HEAD = do_PUT = do_DELETE = \ 303 do_GET = do_POST = do_HEAD = do_PUT = do_DELETE = \
302 do_PATCH = do_OPTIONS = run_cgi 304 do_PATCH = do_OPTIONS = run_cgi
303 305
304 def index(self): 306 def index(self):

Roundup Issue Tracker: http://roundup-tracker.org/