Skip to content

Commit 76c771c

Browse files
committed
fix: roundup-server Content-Length when generating index
Cleanup tracker index generation by roundup-server. Send correct Content-Length headers so HTTP/1.1 connections don't hang. Also added charset to the Content-Type header.
1 parent bfc0f45 commit 76c771c

File tree

2 files changed

+20
-9
lines changed

2 files changed

+20
-9
lines changed

CHANGES.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,9 @@ Fixed:
174174
roundup-server in SSL/TLS mode. Report better error messages
175175
when PEM file is missing certificate or private key. (John
176176
Rouillard)
177+
- Cleanup tracker index generation by roundup-server. Send
178+
correct Content-Length headers so HTTP/1.1 connections don't
179+
hang. (John Rouillard)
177180

178181
Features:
179182

roundup/scripts/roundup_server.py

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -320,12 +320,14 @@ def index(self):
320320
if len(keys) == 1:
321321
self.send_response(302)
322322
self.send_header('Location', urllib_.quote(keys[0]) + '/index')
323+
self.send_header('Content-Length', 0)
323324
self.end_headers()
324-
else:
325-
self.send_response(200)
325+
return
326+
327+
self.send_response(200)
328+
self.send_header('Content-Type', 'text/html; charset=utf-8')
329+
output = []
326330

327-
self.send_header('Content-Type', 'text/html')
328-
self.end_headers()
329331
w = self.wfile.write
330332

331333
if self.CONFIG and self.CONFIG['TEMPLATE']:
@@ -336,16 +338,22 @@ def index(self):
336338
'nothing': None,
337339
'true': 1,
338340
'false': 0}
339-
w(s2b(pt.pt_render(extra_context=extra)))
341+
output.append(s2b(pt.pt_render(extra_context=extra)))
340342
else:
341-
w(s2b(_('<html><head><title>Roundup trackers index</title></head>\n'
342-
'<body><h1>Roundup trackers index</h1><ol>\n')))
343+
output.append(s2b(_(
344+
'<html><head><title>Roundup trackers index</title></head>\n'
345+
'<body><h1>Roundup trackers index</h1><ol>\n')))
343346
keys.sort()
344347
for tracker in keys:
345-
w(s2b('<li><a href="%(tracker_url)s/index">%(tracker_name)s</a>\n' % {
348+
output.append(s2b('<li><a href="%(tracker_url)s/index">%(tracker_name)s</a>\n' % {
346349
'tracker_url': urllib_.quote(tracker),
347350
'tracker_name': html_escape(tracker)}))
348-
w(b'</ol></body></html>')
351+
output.append(b'</ol></body></html>\n')
352+
353+
write_output = b"\n".join(output)
354+
self.send_header('Content-Length', len(write_output))
355+
self.end_headers()
356+
w(write_output)
349357

350358
def inner_run_cgi(self):
351359
''' This is the inner part of the CGI handling

0 commit comments

Comments
 (0)