Merge pull request #1564 from mhils/issue-1554

Fix Response.make content-length header
This commit is contained in:
Maximilian Hils 2016-09-21 21:49:14 -07:00 committed by GitHub
commit 9e0b935fa2
2 changed files with 15 additions and 9 deletions

View File

@ -84,15 +84,6 @@ class Response(message.Message):
(),
None
)
# Assign this manually to update the content-length header.
if isinstance(content, bytes):
resp.content = content
elif isinstance(content, str):
resp.text = content
else:
raise TypeError("Expected content to be str or bytes, but is {}.".format(
type(content).__name__
))
# Headers can be list or dict, we differentiate here.
if isinstance(headers, dict):
@ -104,6 +95,16 @@ class Response(message.Message):
type(headers).__name__
))
# Assign this manually to update the content-length header.
if isinstance(content, bytes):
resp.content = content
elif isinstance(content, str):
resp.text = content
else:
raise TypeError("Expected content to be str or bytes, but is {}.".format(
type(content).__name__
))
return resp
@property

View File

@ -34,6 +34,11 @@ class TestResponseCore(object):
assert r.status_code == 200
assert r.content == b""
r = Response.make(418, "teatime")
assert r.status_code == 418
assert r.content == b"teatime"
assert r.headers["content-length"] == "7"
Response.make(content=b"foo")
Response.make(content="foo")
with raises(TypeError):