base: Set response charset

WebOb has started raising an exception when writing a Unicode string to
`Response` objects if no charset is set.
master
Dustin 2023-12-15 14:26:53 -06:00
parent 9023294c60
commit 810f7d07b8
1 changed files with 2 additions and 0 deletions

View File

@ -30,10 +30,12 @@ class VariedResponse(milla.Response):
context = {} context = {}
if template is None or self.request.want == 'json': if template is None or self.request.want == 'json':
self.content_type = str('application/json') self.content_type = str('application/json')
self.charset = 'utf-8'
json.dump(context, self.body_file) json.dump(context, self.body_file)
else: else:
if self.request.want == 'xhtml': if self.request.want == 'xhtml':
self.content_type = str('application/xhtml+xml') self.content_type = str('application/xhtml+xml')
self.charset = 'utf-8'
self.render(template, context) self.render(template, context)
def render(self, template, context=None): def render(self, template, context=None):