diff roundup/cgi/client.py @ 6548:de5f5f9c02f2

Fix spurious content-ty on 304; xfail css Cache-Control Using wsgiref.validate.validator to verify http/wsgi responses. It discovered that a 304 was returning a content-type header but shouldn't. Fixed that. For some unknown reason I can't reproduce on my devel platform, travis-ci is throwing: > self.assertEqual(f.headers['Cache-Control'], 'public, max-age=4838400') E AssertionError: 'public, max-age=3600' != 'public, max-age=4838400' E - public, max-age=3600 E ? ^ E + public, max-age=4838400 E ? ++ ^^ in test_liveserver test_cache_control_css. I have no idea why this is happening. The 3600 value isn't in the code base or tracker template that I see. While I was trying to figure out if the wsgi server later was an issue, I came across the validator. Maybe it will throw some light on this error?
author John Rouillard <rouilj@ieee.org>
date Thu, 09 Dec 2021 20:11:58 -0500
parents c58c7cd31243
children 15ae655c2014
line wrap: on
line diff
--- a/roundup/cgi/client.py	Thu Dec 09 17:38:54 2021 -0500
+++ b/roundup/cgi/client.py	Thu Dec 09 20:11:58 2021 -0500
@@ -1781,7 +1781,6 @@
         """
 
         # spit out headers
-        self.additional_headers['Content-Type'] = mime_type
         self.additional_headers['Last-Modified'] = email.utils.formatdate(lmt)
 
         ims = None
@@ -1802,6 +1801,9 @@
                     self.setVary("Accept-Encoding")
                 raise NotModified
 
+        # don't set until we are sure we are sending a response body.
+        self.additional_headers['Content-Type'] = mime_type
+
         if filename:
             self.write_file(filename)
         else:
@@ -2519,7 +2521,7 @@
         if headers.get('Content-Type', 'text/html') == 'text/html':
             headers['Content-Type'] = 'text/html; charset=utf-8'
 
-        if response == 204: # has no body so no content-type
+        if response in [ 204, 304]: # has no body so no content-type
             del(headers['Content-Type'])
 
         headers = list(headers.items())

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