Mercurial > p > roundup > code
diff roundup/cgi/client.py @ 6509:1fc765ef6379
Fix 204 responses, hangs and crashes with REST.
Remove Content-Type and make sure no content is returned by OPTIONS
request in REST interface.
In write_html set the Content-Length when response is not
encoded/compressed (fixes hang due to missing content-length with
unencoded data).
In REST interface do not raise UsageError for invalid api version.
Return json error with proper message. Fixes crash.
| author | John Rouillard <rouilj@ieee.org> |
|---|---|
| date | Sat, 16 Oct 2021 13:34:04 -0400 |
| parents | e162845193c4 |
| children | f8df7fed18f6 |
line wrap: on
line diff
--- a/roundup/cgi/client.py Fri Oct 08 00:35:09 2021 -0400 +++ b/roundup/cgi/client.py Sat Oct 16 13:34:04 2021 -0400 @@ -645,8 +645,11 @@ # type header set by rest handler # self.setHeader("Content-Type", "text/xml") - self.setHeader("Content-Length", str(len(output))) - self.write(output) + if self.response_code == 204: # no body with 204 + self.write("") + else: + self.setHeader("Content-Length", str(len(output))) + self.write(output) def add_ok_message(self, msg, escape=True): add_message(self._ok_message, msg, escape) @@ -848,7 +851,7 @@ else: # in debug mode, only write error to screen. self.write_html(e.html) - except: + except Exception as e: # Something has gone badly wrong. Therefore, we should # make sure that the response code indicates failure. if self.response_code == http_.client.OK: @@ -2196,6 +2199,8 @@ if 'Content-Type' not in self.additional_headers: self.additional_headers['Content-Type'] = \ 'text/html; charset=%s' % self.charset + if 'Content-Length' not in self.additional_headers: + self.additional_headers['Content-Length'] = len(content) self.header() if self.env['REQUEST_METHOD'] == 'HEAD': @@ -2497,6 +2502,9 @@ 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 + del(headers['Content-Type']) + headers = list(headers.items()) for ((path, name), (value, expire)) in self._cookies.items():
