def default_addons(): return [ core.Core(), browser.Browser(), block.Block(), blocklist.BlockList(), anticache.AntiCache(), anticomp.AntiComp(), clientplayback.ClientPlayback(), command_history.CommandHistory(), comment.Comment(), cut.Cut(), disable_h2c.DisableH2C(), export.Export(), onboarding.Onboarding(), proxyauth.ProxyAuth(), proxyserver.Proxyserver(), script.ScriptLoader(), next_layer.NextLayer(), serverplayback.ServerPlayback(), mapremote.MapRemote(), maplocal.MapLocal(), modifybody.ModifyBody(), modifyheaders.ModifyHeaders(), stickyauth.StickyAuth(), stickycookie.StickyCookie(), save.Save(), tlsconfig.TlsConfig(), upstream_auth.UpstreamAuth(), ]
def default_addons(): return [ core.Core(), browser.Browser(), block.Block(), anticache.AntiCache(), anticomp.AntiComp(), check_ca.CheckCA(), clientplayback.ClientPlayback(), command_history.CommandHistory(), cut.Cut(), disable_h2c.DisableH2C(), export.Export(), onboarding.Onboarding(), proxyauth.ProxyAuth(), script.ScriptLoader(), serverplayback.ServerPlayback(), mapremote.MapRemote(), modifybody.ModifyBody(), modifyheaders.ModifyHeaders(), stickyauth.StickyAuth(), stickycookie.StickyCookie(), streambodies.StreamBodies(), save.Save(), upstream_auth.UpstreamAuth(), ]
def test_configure(self): sh = modifyheaders.ModifyHeaders() with taddons.context(sh) as tctx: with pytest.raises(Exception, match="Invalid modify_headers flow filter"): tctx.configure(sh, modify_headers=["/one/two/~b"]) tctx.configure(sh, modify_headers=["/foo/bar/voing"])
def test_configure(self): mh = modifyheaders.ModifyHeaders() with taddons.context(mh) as tctx: with pytest.raises(Exception, match="Cannot parse modify_headers .* Invalid number"): tctx.configure(mh, modify_headers = ["/"]) with pytest.raises(Exception, match="Cannot parse modify_headers .* Invalid filter"): tctx.configure(mh, modify_headers = ["/~b/one/two"]) with pytest.raises(Exception, match="Cannot parse modify_headers .* Invalid file"): tctx.configure(mh, modify_headers = ["/~q/foo/@nonexistent"]) tctx.configure(mh, modify_headers = ["/foo/bar/voing"])
def test_simple(self, tmpdir): mh = modifyheaders.ModifyHeaders() with taddons.context(mh) as tctx: tmpfile = tmpdir.join("replacement") tmpfile.write("two") tctx.configure( mh, modify_headers=["/~q/one/@" + str(tmpfile)] ) f = tflow.tflow() f.request.headers["one"] = "xxx" mh.request(f) assert f.request.headers["one"] == "two"
def test_modify_headers(self): sh = modifyheaders.ModifyHeaders() with taddons.context(sh) as tctx: tctx.configure(sh, modify_headers=["/one/two/~q", "/one/three/~s"]) 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, modify_headers=["/one/two/~s", "/one/three/~s"]) 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, modify_headers=["/one/two/~q", "/one/three/~q"]) f = tflow.tflow() f.request.headers["one"] = "xxx" sh.request(f) assert f.request.headers.get_all("one") == ["two", "three"] # test removal of existing headers tctx.configure(sh, modify_headers=["/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, modify_headers=["/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
async def test_nonexistent(self, tmpdir): mh = modifyheaders.ModifyHeaders() with taddons.context(mh) as tctx: with pytest.raises(Exception, match="Cannot parse modify_headers .* Invalid file path"): tctx.configure( mh, modify_headers=["/~q/foo/@nonexistent"] ) tmpfile = tmpdir.join("replacement") tmpfile.write("bar") tctx.configure( mh, modify_headers=["/~q/foo/@" + str(tmpfile)] ) tmpfile.remove() f = tflow.tflow() f.request.content = b"foo" mh.request(f) assert await tctx.master.await_log("could not read")