mirror of
https://github.com/Grasscutters/mitmproxy.git
synced 2024-11-23 00:01:36 +00:00
Merge pull request #1564 from mhils/issue-1554
Fix Response.make content-length header
This commit is contained in:
commit
9e0b935fa2
@ -84,15 +84,6 @@ class Response(message.Message):
|
|||||||
(),
|
(),
|
||||||
None
|
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.
|
# Headers can be list or dict, we differentiate here.
|
||||||
if isinstance(headers, dict):
|
if isinstance(headers, dict):
|
||||||
@ -104,6 +95,16 @@ class Response(message.Message):
|
|||||||
type(headers).__name__
|
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
|
return resp
|
||||||
|
|
||||||
@property
|
@property
|
||||||
|
@ -34,6 +34,11 @@ class TestResponseCore(object):
|
|||||||
assert r.status_code == 200
|
assert r.status_code == 200
|
||||||
assert r.content == b""
|
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=b"foo")
|
||||||
Response.make(content="foo")
|
Response.make(content="foo")
|
||||||
with raises(TypeError):
|
with raises(TypeError):
|
||||||
|
Loading…
Reference in New Issue
Block a user