Mercurial > p > roundup > code
diff roundup/cgi/client.py @ 7805:cc4b11ab2f22
fix: if Content-Type header defined, don't overwrite with default
When processing a template, you should be able to set the content-type
header using:
tal:replace="python:request.client.additional_headers.update(
{'Content-Type':'application/vnd.roundup.translation+json'}
)"
The client used to always overwrite it with the content type derived
from the template extension or text/html for unknown extensions. This
patch stops the overwriting if the Content-Type is already set in the
header.
This particular use case was to use an XML document to process a url
like:
/tracker?@template=translation+json&tokens=Login,Welcome+%s
and get back json data of the translated strings. If the file was
named '_generic.json' and we used '@template=json' we got
application/json returned. For other template names we got text/html.
| author | John Rouillard <rouilj@ieee.org> |
|---|---|
| date | Wed, 13 Mar 2024 17:53:05 -0400 |
| parents | 7102de2c8733 |
| children | be6cb2e0d471 |
line wrap: on
line diff
--- a/roundup/cgi/client.py Wed Mar 13 13:14:09 2024 -0400 +++ b/roundup/cgi/client.py Wed Mar 13 17:53:05 2024 -0400 @@ -2132,7 +2132,8 @@ except IndexerQueryError as e: result = self.renderError(e.args[0]) - self.additional_headers['Content-Type'] = pt.content_type + if 'Content-Type' not in self.additional_headers: + self.additional_headers['Content-Type'] = pt.content_type if self.env.get('CGI_SHOW_TIMING', ''): if self.env['CGI_SHOW_TIMING'].upper() == 'COMMENT': timings = {'starttag': '<!-- ', 'endtag': ' -->'}
