1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
|
from mitmproxy.test import tflow
from mitmproxy.test import tutils
from mitmproxy.test import taddons
from mitmproxy.addons import setheaders
from mitmproxy import options
class TestSetHeaders:
def test_configure(self):
sh = setheaders.SetHeaders()
o = options.Options(
setheaders = [("~b", "one", "two")]
)
tutils.raises(
"invalid setheader filter pattern",
sh.configure, o, o.keys()
)
def test_setheaders(self):
sh = setheaders.SetHeaders()
with taddons.context() as tctx:
tctx.configure(
sh,
setheaders = [
("~q", "one", "two"),
("~s", "one", "three")
]
)
f = tflow.tflow()
f.request.headers["one"] = "xxx"
sh.request(f)
assert f.request.headers["one"] == "two"
f = tflow.tflow(resp=True)
f.response.headers["one"] = "xxx"
sh.response(f)
assert f.response.headers["one"] == "three"
tctx.configure(
sh,
setheaders = [
("~s", "one", "two"),
("~s", "one", "three")
]
)
f = tflow.tflow(resp=True)
f.request.headers["one"] = "xxx"
f.response.headers["one"] = "xxx"
sh.response(f)
assert f.response.headers.get_all("one") == ["two", "three"]
tctx.configure(
sh,
setheaders = [
("~q", "one", "two"),
("~q", "one", "three")
]
)
f = tflow.tflow()
f.request.headers["one"] = "xxx"
sh.request(f)
assert f.request.headers.get_all("one") == ["two", "three"]
|