cuts: don't crash when retrieving header of a non-existent response

This commit is contained in:
Aldo Cortesi 2017-12-20 11:53:44 +13:00
parent 2fd5bbe1e7
commit 7d45d7f15e
2 changed files with 7 additions and 0 deletions

View file

@ -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

View file

@ -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()]