mirror of
https://github.com/Grasscutters/mitmproxy.git
synced 2024-11-30 03:14:22 +00:00
fix Response.make content-length header
This commit is contained in:
parent
1e5a5b03f8
commit
0b532789a0
@ -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
|
||||
|
@ -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):
|
||||
|
Loading…
Reference in New Issue
Block a user