Skip to content

Commit

Permalink
Explicitly set application/json content type for JSON responses and d…
Browse files Browse the repository at this point in the history
…eclare an utf-8 charset.
  • Loading branch information
thet committed Aug 1, 2016
1 parent f22b950 commit f21cf25
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 5 deletions.
3 changes: 3 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ New features:

Bug fixes:

- Explicitly set ``application/json`` content type for JSON responses and declare an ``utf-8`` charset.
[thet]

- Properly deprecated ``_permissions`` in favor of ``PERMISSIONS``.
Since 3.1, the ``_permissions`` variable was ``None`` instead of a
backwards compatibility alias for ``PERMISSIONS`` due to a wrong
Expand Down
11 changes: 10 additions & 1 deletion plone/app/content/browser/contents/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,9 @@ def protect(self):
checkpost(self.request)

def json(self, data):
self.request.response.setHeader("Content-Type", "application/json")
self.request.response.setHeader(
'Content-Type', 'application/json; charset=utf-8'
)
return json_dumps(data)

def get_selection(self):
Expand Down Expand Up @@ -283,6 +285,9 @@ def get_options(self):
return options

def __call__(self):
self.request.response.setHeader(
'Content-Type', 'application/json; charset=utf-8'
)
self.options = json_dumps(self.get_options())
return super(FolderContentsView, self).__call__()

Expand Down Expand Up @@ -360,6 +365,10 @@ def __call__(self):
if key == 'path':
val = val[len(base_path):]
item[key] = val

self.request.response.setHeader(
'Content-Type', 'application/json; charset=utf-8'
)
return json_dumps({
'addButtons': factories,
'defaultPage': self.context.getDefaultPage(),
Expand Down
4 changes: 3 additions & 1 deletion plone/app/content/browser/contents/delete.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,9 @@ def __call__(self):
catalog = getToolByName(self.context, 'portal_catalog')
brains = catalog(UID=selection)
items = [i.getObject() for i in brains]
self.request.response.setHeader('Content-Type', 'application/json')
self.request.response.setHeader(
'Content-Type', 'application/json; charset=utf-8'
)
return json.dumps({
'html': confirm_view(items)
})
Expand Down
4 changes: 4 additions & 0 deletions plone/app/content/browser/file.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,4 +187,8 @@ def __call__(self):
'UID': IUUID(obj),
'filename': filename
})

self.request.response.setHeader(
'Content-Type', 'application/json; charset=utf-8'
)
return json.dumps(result)
2 changes: 1 addition & 1 deletion plone/app/content/browser/i18n.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,6 @@ def __call__(self, domain, language=None):

catalog = self._gettext_catalog(domain, language)
response = self.request.response
response.setHeader('content-type', 'application/json')
response.setHeader('Content-Type', 'application/json; charset=utf-8')
response.setBody(json.dumps(catalog))
return response
4 changes: 3 additions & 1 deletion plone/app/content/browser/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,7 @@ class QueryStringIndexOptions(BrowserView):
def __call__(self):
registry = getUtility(IRegistry)
config = IQuerystringRegistryReader(registry)()
self.request.response.setHeader("Content-Type", "application/json")
self.request.response.setHeader(
'Content-Type', 'application/json; charset=utf-8'
)
return json.dumps(config)
4 changes: 3 additions & 1 deletion plone/app/content/browser/vocabulary.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,9 @@ def __call__(self):
}
"""
context = self.get_context()
self.request.response.setHeader("Content-type", "application/json")
self.request.response.setHeader(
'Content-Type', 'application/json; charset=utf-8'
)

try:
vocabulary = self.get_vocabulary()
Expand Down

0 comments on commit f21cf25

Please sign in to comment.