mirror of
https://github.com/Grasscutters/mitmproxy.git
synced 2024-11-26 18:18:25 +00:00
parent
46901d1d55
commit
5067438ec1
@ -210,7 +210,11 @@ def expected_http_body_size(request, response=None):
|
|||||||
return None
|
return None
|
||||||
if "content-length" in headers:
|
if "content-length" in headers:
|
||||||
try:
|
try:
|
||||||
size = int(headers["content-length"])
|
sizes = headers.get_all("content-length")
|
||||||
|
different_content_length_headers = any(x != sizes[0] for x in sizes)
|
||||||
|
if different_content_length_headers:
|
||||||
|
raise exceptions.HttpSyntaxException("Conflicting Content Length Headers")
|
||||||
|
size = int(sizes[0])
|
||||||
if size < 0:
|
if size < 0:
|
||||||
raise ValueError()
|
raise ValueError()
|
||||||
return size
|
return size
|
||||||
|
@ -194,6 +194,17 @@ def test_expected_http_body_size():
|
|||||||
treq(headers=Headers(content_length="42"))
|
treq(headers=Headers(content_length="42"))
|
||||||
) == 42
|
) == 42
|
||||||
|
|
||||||
|
# more than 1 content-length headers with same value
|
||||||
|
assert expected_http_body_size(
|
||||||
|
treq(headers=Headers([(b'content-length', b'42'), (b'content-length', b'42')]))
|
||||||
|
) == 42
|
||||||
|
|
||||||
|
# more than 1 content-length headers with conflicting value
|
||||||
|
with pytest.raises(exceptions.HttpSyntaxException):
|
||||||
|
expected_http_body_size(
|
||||||
|
treq(headers=Headers([(b'content-length', b'42'), (b'content-length', b'45')]))
|
||||||
|
)
|
||||||
|
|
||||||
# no length
|
# no length
|
||||||
assert expected_http_body_size(
|
assert expected_http_body_size(
|
||||||
treq(headers=Headers())
|
treq(headers=Headers())
|
||||||
|
Loading…
Reference in New Issue
Block a user