Response model now handles the 204 no content
This commit is contained in:
@@ -195,8 +195,12 @@ class HTTPResponse(BaseHTTPResponse):
|
||||
timeout_header = b''
|
||||
if keep_alive and keep_alive_timeout is not None:
|
||||
timeout_header = b'Keep-Alive: %d\r\n' % keep_alive_timeout
|
||||
self.headers['Content-Length'] = self.headers.get(
|
||||
'Content-Length', len(self.body))
|
||||
|
||||
content_length = 0
|
||||
if self.status is not 204:
|
||||
content_length = self.headers.get('Content-Length', len(self.body))
|
||||
self.headers['Content-Length'] = content_length
|
||||
|
||||
self.headers['Content-Type'] = self.headers.get(
|
||||
'Content-Type', self.content_type)
|
||||
|
||||
@@ -218,7 +222,7 @@ class HTTPResponse(BaseHTTPResponse):
|
||||
b'keep-alive' if keep_alive else b'close',
|
||||
timeout_header,
|
||||
headers,
|
||||
self.body
|
||||
self.body if self.status is not 204 else b''
|
||||
)
|
||||
|
||||
@property
|
||||
@@ -239,8 +243,7 @@ def json(body, status=200, headers=None,
|
||||
:param headers: Custom Headers.
|
||||
:param kwargs: Remaining arguments that are passed to the json encoder.
|
||||
"""
|
||||
_body = dumps(body, **kwargs) if body else None
|
||||
return HTTPResponse(_body, headers=headers,
|
||||
return HTTPResponse(dumps(body, **kwargs), headers=headers,
|
||||
status=status, content_type=content_type)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user