aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--netlib/http/response.py19
-rw-r--r--test/netlib/http/test_response.py5
2 files changed, 15 insertions, 9 deletions
diff --git a/netlib/http/response.py b/netlib/http/response.py
index ae29298f..385e233a 100644
--- a/netlib/http/response.py
+++ b/netlib/http/response.py
@@ -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
diff --git a/test/netlib/http/test_response.py b/test/netlib/http/test_response.py
index c7b1b646..e97cc419 100644
--- a/test/netlib/http/test_response.py
+++ b/test/netlib/http/test_response.py
@@ -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):