mirror of
https://github.com/Grasscutters/mitmproxy.git
synced 2024-11-26 02:10:59 +00:00
setheaders addon: removal of existing headers
This commit is contained in:
parent
b6c70950c3
commit
ccf7182a11
@ -50,7 +50,7 @@ class SetHeaders:
|
|||||||
"setheaders", typing.Sequence[str], [],
|
"setheaders", typing.Sequence[str], [],
|
||||||
"""
|
"""
|
||||||
Header set pattern of the form "/header-name/header-value[/flow-filter]", where the
|
Header set pattern of the form "/header-name/header-value[/flow-filter]", where the
|
||||||
separator can be any character.
|
separator can be any character. An empty header-value removes existing header-name headers.
|
||||||
"""
|
"""
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -72,7 +72,7 @@ class SetHeaders:
|
|||||||
if flow_filter(f):
|
if flow_filter(f):
|
||||||
hdrs.pop(header, None)
|
hdrs.pop(header, None)
|
||||||
for header, value, _, flow_filter in self.lst:
|
for header, value, _, flow_filter in self.lst:
|
||||||
if flow_filter(f):
|
if flow_filter(f) and value:
|
||||||
hdrs.add(header, value)
|
hdrs.add(header, value)
|
||||||
|
|
||||||
def request(self, flow):
|
def request(self, flow):
|
||||||
|
@ -68,3 +68,37 @@ class TestSetHeaders:
|
|||||||
f.request.headers["one"] = "xxx"
|
f.request.headers["one"] = "xxx"
|
||||||
sh.request(f)
|
sh.request(f)
|
||||||
assert f.request.headers.get_all("one") == ["two", "three"]
|
assert f.request.headers.get_all("one") == ["two", "three"]
|
||||||
|
|
||||||
|
# test removal of existing header
|
||||||
|
tctx.configure(
|
||||||
|
sh,
|
||||||
|
setheaders = [
|
||||||
|
"/one//~q",
|
||||||
|
"/one//~s"
|
||||||
|
]
|
||||||
|
)
|
||||||
|
f = tflow.tflow()
|
||||||
|
f.request.headers["one"] = "xxx"
|
||||||
|
sh.request(f)
|
||||||
|
assert "one" not in f.request.headers
|
||||||
|
|
||||||
|
f = tflow.tflow(resp=True)
|
||||||
|
f.response.headers["one"] = "xxx"
|
||||||
|
sh.response(f)
|
||||||
|
assert "one" not in f.response.headers
|
||||||
|
|
||||||
|
tctx.configure(
|
||||||
|
sh,
|
||||||
|
setheaders = [
|
||||||
|
"/one/"
|
||||||
|
]
|
||||||
|
)
|
||||||
|
f = tflow.tflow()
|
||||||
|
f.request.headers["one"] = "xxx"
|
||||||
|
sh.request(f)
|
||||||
|
assert "one" not in f.request.headers
|
||||||
|
|
||||||
|
f = tflow.tflow(resp=True)
|
||||||
|
f.response.headers["one"] = "xxx"
|
||||||
|
sh.response(f)
|
||||||
|
assert "one" not in f.response.headers
|
Loading…
Reference in New Issue
Block a user