From ccbdcd684b5a49c0509610a79dad3f220962a42d Mon Sep 17 00:00:00 2001 From: "Tyler St. Onge" Date: Sat, 1 Oct 2016 07:06:59 -0400 Subject: [PATCH] Add API to programmatically create new requests (#1534) --- mitmproxy/flow/master.py | 4 ++++ test/mitmproxy/test_flow.py | 9 +++++++++ 2 files changed, 13 insertions(+) diff --git a/mitmproxy/flow/master.py b/mitmproxy/flow/master.py index 80f633cd6..144323576 100644 --- a/mitmproxy/flow/master.py +++ b/mitmproxy/flow/master.py @@ -187,6 +187,10 @@ class FlowMaster(controller.Master): rt.join() return rt + def new_request(self, method, scheme, host, port, path, block=False): + f = self.create_request(method, scheme, host, port, path) + return self.replay_request(f, block) + @controller.handler def log(self, l): self.add_log(l.msg, l.level) diff --git a/test/mitmproxy/test_flow.py b/test/mitmproxy/test_flow.py index 0fe45afb2..821263538 100644 --- a/test/mitmproxy/test_flow.py +++ b/test/mitmproxy/test_flow.py @@ -463,6 +463,15 @@ class TestFlowMaster: assert s.flow_count() == 2 assert s.index(f2) == 1 + def test_new_request(self): + s = flow.State() + fm = flow.FlowMaster( + options.Options(), + DummyServer(ProxyConfig(options.Options())), + s + ) + assert fm.new_request("GET", "http", "example.com", 80, "/") + def test_create_flow(self): s = flow.State() fm = flow.FlowMaster(None, None, s)