Skip to content

Commit cc78e66

Browse files
committed
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.
1 parent bd80f14 commit cc78e66

File tree

2 files changed

+16
-12
lines changed

2 files changed

+16
-12
lines changed

CHANGES.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,9 @@ Fixed:
5454
roundup-admin. (John Rouillard)
5555
- Document better that files in the template or static_files
5656
directories accessed via @@file are available to any user with the
57-
url.
57+
url. (John Rouillard)
58+
- Fix final exception handler in roundup-server to send proper
59+
Content-Length header to the client. (John Rouillard)
5860

5961
Features:
6062

roundup/scripts/roundup_server.py

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -272,32 +272,34 @@ def run_cgi(self):
272272
if hasattr(socket, 'timeout') and isinstance(val, socket.timeout):
273273
self.log_error('timeout')
274274
else:
275-
# it'd be nice to be able to detect if these are going to have
276-
# any effect...
277275
self.send_response(400)
278276
self.send_header('Content-Type', 'text/html')
279-
self.end_headers()
280277
if self.DEBUG_MODE:
281278
try:
282279
reload(cgitb)
283-
self.wfile.write(s2b(cgitb.breaker()))
284-
self.wfile.write(s2b(cgitb.html()))
280+
output = s2b(cgitb.breaker()) + s2b(cgitb.html())
285281
except Exception:
286282
s = StringIO()
287283
traceback.print_exc(None, s)
288-
self.wfile.write(b"<pre>")
289-
self.wfile.write(s2b(html_escape(s.getvalue())))
290-
self.wfile.write(b"</pre>\n")
284+
output = b"<pre>%s</pre>" % s2b(
285+
html_escape(s.getvalue()))
291286
else:
292287
# user feedback
293-
self.wfile.write(s2b(cgitb.breaker()))
294288
ts = time.ctime()
295-
self.wfile.write(s2b('''<p>%s: An error occurred. Please check
296-
the server log for more information.</p>''' % ts))
289+
output = (
290+
s2b('''<body><p>%s: An error occurred. Please check
291+
the server log for more information.</p></body>''' %
292+
ts)
293+
)
297294
# out to the logfile
298295
print('EXCEPTION AT', ts)
299296
traceback.print_exc()
300297

298+
# complete output to user.
299+
self.send_header('Content-Length', len(output))
300+
self.end_headers()
301+
self.wfile.write(output)
302+
301303
do_GET = do_POST = do_HEAD = do_PUT = do_DELETE = \
302304
do_PATCH = do_OPTIONS = run_cgi
303305

0 commit comments

Comments
 (0)