comparison roundup/scripts/roundup_server.py @ 8038:5a122373641a

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.
author John Rouillard <rouilj@ieee.org>
date Mon, 17 Jun 2024 23:18:37 -0400
parents 0f5d31be5418
children 627c5d6a0551
comparison
equal deleted inserted replaced
8037:2acfcbdf052f 8038:5a122373641a
318 ''' 318 '''
319 keys = list(self.TRACKER_HOMES.keys()) 319 keys = list(self.TRACKER_HOMES.keys())
320 if len(keys) == 1: 320 if len(keys) == 1:
321 self.send_response(302) 321 self.send_response(302)
322 self.send_header('Location', urllib_.quote(keys[0]) + '/index') 322 self.send_header('Location', urllib_.quote(keys[0]) + '/index')
323 self.send_header('Content-Length', 0)
323 self.end_headers() 324 self.end_headers()
324 else: 325 return
325 self.send_response(200) 326
326 327 self.send_response(200)
327 self.send_header('Content-Type', 'text/html') 328 self.send_header('Content-Type', 'text/html; charset=utf-8')
328 self.end_headers() 329 output = []
330
329 w = self.wfile.write 331 w = self.wfile.write
330 332
331 if self.CONFIG and self.CONFIG['TEMPLATE']: 333 if self.CONFIG and self.CONFIG['TEMPLATE']:
332 template = open(self.CONFIG['TEMPLATE']).read() 334 template = open(self.CONFIG['TEMPLATE']).read()
333 pt = PageTemplate() 335 pt = PageTemplate()
334 pt.write(template) 336 pt.write(template)
335 extra = {'trackers': self.TRACKERS, 337 extra = {'trackers': self.TRACKERS,
336 'nothing': None, 338 'nothing': None,
337 'true': 1, 339 'true': 1,
338 'false': 0} 340 'false': 0}
339 w(s2b(pt.pt_render(extra_context=extra))) 341 output.append(s2b(pt.pt_render(extra_context=extra)))
340 else: 342 else:
341 w(s2b(_('<html><head><title>Roundup trackers index</title></head>\n' 343 output.append(s2b(_(
342 '<body><h1>Roundup trackers index</h1><ol>\n'))) 344 '<html><head><title>Roundup trackers index</title></head>\n'
345 '<body><h1>Roundup trackers index</h1><ol>\n')))
343 keys.sort() 346 keys.sort()
344 for tracker in keys: 347 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' % {
346 'tracker_url': urllib_.quote(tracker), 349 'tracker_url': urllib_.quote(tracker),
347 'tracker_name': html_escape(tracker)})) 350 '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)
349 357
350 def inner_run_cgi(self): 358 def inner_run_cgi(self):
351 ''' This is the inner part of the CGI handling 359 ''' This is the inner part of the CGI handling
352 ''' 360 '''
353 361

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