mirror of
https://github.com/vee1e/mitmproxy.git
synced 2026-09-02 02:37:15 +00:00
cuts: don't crash when retrieving header of a non-existent response
This commit is contained in:
parent
2fd5bbe1e7
commit
7d45d7f15e
2 changed files with 7 additions and 0 deletions
|
|
@ -36,6 +36,8 @@ def extract(cut: str, f: flow.Flow) -> typing.Union[str, bytes]:
|
|||
if spec == "host" and is_addr(current):
|
||||
return str(current[0])
|
||||
elif spec.startswith("header["):
|
||||
if not current:
|
||||
return ""
|
||||
return current.headers.get(headername(spec), "")
|
||||
elif isinstance(part, bytes):
|
||||
return part
|
||||
|
|
|
|||
|
|
@ -135,6 +135,11 @@ def test_cut():
|
|||
with pytest.raises(exceptions.CommandError):
|
||||
assert c.cut(tflows, ["__dict__"]) == [[""]]
|
||||
|
||||
with taddons.context():
|
||||
tflows = [tflow.tflow(resp=False)]
|
||||
assert c.cut(tflows, ["response.reason"]) == [[""]]
|
||||
assert c.cut(tflows, ["response.header[key]"]) == [[""]]
|
||||
|
||||
c = cut.Cut()
|
||||
with taddons.context():
|
||||
tflows = [tflow.ttcpflow()]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue