Skip to content
This repository has been archived by the owner on Apr 9, 2023. It is now read-only.

Commit

Permalink
do not set content type header if already defined on resp
Browse files Browse the repository at this point in the history
  • Loading branch information
vangheem committed Jan 10, 2017
1 parent 42428ff commit b9be8b9
Showing 1 changed file with 26 additions and 19 deletions.
45 changes: 26 additions & 19 deletions src/plone.server/plone/server/renderers.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,24 +133,31 @@ async def __call__(self, value):
@adapter(IRendererFormatRaw, IView, IRequest)
@implementer(IRendered)
class RendererRaw(Renderer):

def guess_response(self, value):
resp = value.response
if isinstance(resp, dict):
resp = aioResponse(body=bytes(json.dumps(resp), 'utf-8'))
resp.headers['Content-Type'] = 'application/json'
elif isinstance(resp, list):
resp = aioResponse(body=bytes(json.dumps(resp), 'utf-8'))
resp.headers['Content-Type'] = 'application/json'
elif isinstance(resp, str):
resp = aioResponse(body=bytes(resp, 'utf-8'))
resp.headers['Content-Type'] = 'text/html'
elif resp is None:
# missing result...
resp = aioResponse(body=b'{}')
resp.headers['Content-Type'] = 'application/json'

resp.headers.update(value.headers)
resp.set_status(value.status)
return resp

async def __call__(self, value):
if hasattr(value, '__class__') and issubclass(value.__class__, Response):
resp = value.response
if isinstance(resp, dict):
resp = aioResponse(body=bytes(json.dumps(resp), 'utf-8'))
resp.headers['Content-Type'] = 'application/json'
elif isinstance(resp, list):
resp = aioResponse(body=bytes(json.dumps(resp), 'utf-8'))
resp.headers['Content-Type'] = 'application/json'
elif isinstance(resp, str):
resp = aioResponse(body=bytes(resp, 'utf-8'))
resp.headers['Content-Type'] = 'text/html'
elif resp is None:
# missing result...
resp = aioResponse(body=b'{}')
resp.headers['Content-Type'] = 'application/json'
resp.headers.update(value.headers)
resp.set_status(value.status)
else:
resp = value
resp = value
if (hasattr(value, '__class__') and
issubclass(value.__class__, Response) and
'Content-Type' not in value.headers):
resp = self.guess_response(value)
return resp

0 comments on commit b9be8b9

Please sign in to comment.