Mercurial > p > roundup > code
comparison 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 |
comparison
equal
deleted
inserted
replaced
| 7804:aedc1782a6af | 7805:cc4b11ab2f22 |
|---|---|
| 2130 try: | 2130 try: |
| 2131 result = pt.render(self, None, None, **args) | 2131 result = pt.render(self, None, None, **args) |
| 2132 except IndexerQueryError as e: | 2132 except IndexerQueryError as e: |
| 2133 result = self.renderError(e.args[0]) | 2133 result = self.renderError(e.args[0]) |
| 2134 | 2134 |
| 2135 self.additional_headers['Content-Type'] = pt.content_type | 2135 if 'Content-Type' not in self.additional_headers: |
| 2136 self.additional_headers['Content-Type'] = pt.content_type | |
| 2136 if self.env.get('CGI_SHOW_TIMING', ''): | 2137 if self.env.get('CGI_SHOW_TIMING', ''): |
| 2137 if self.env['CGI_SHOW_TIMING'].upper() == 'COMMENT': | 2138 if self.env['CGI_SHOW_TIMING'].upper() == 'COMMENT': |
| 2138 timings = {'starttag': '<!-- ', 'endtag': ' -->'} | 2139 timings = {'starttag': '<!-- ', 'endtag': ' -->'} |
| 2139 else: | 2140 else: |
| 2140 timings = {'starttag': '<p>', 'endtag': '</p>'} | 2141 timings = {'starttag': '<p>', 'endtag': '</p>'} |
