From ba42984b593246b0105a077311e16a2ca71f79eb Mon Sep 17 00:00:00 2001 From: Marcelo Glezer Date: Tue, 10 Feb 2015 15:24:21 -0300 Subject: added support for creating new requests. still wip (not working for https) --- libmproxy/console/common.py | 11 +++++++++++ libmproxy/console/flowlist.py | 29 +++++++++++++++++++++++++++++ libmproxy/console/flowview.py | 14 ++------------ libmproxy/flow.py | 9 +++++++++ 4 files changed, 51 insertions(+), 12 deletions(-) diff --git a/libmproxy/console/common.py b/libmproxy/console/common.py index e4a4acba..a2cfd57b 100644 --- a/libmproxy/console/common.py +++ b/libmproxy/console/common.py @@ -17,6 +17,17 @@ VIEW_FLOW = 1 VIEW_FLOW_REQUEST = 0 VIEW_FLOW_RESPONSE = 1 +METHOD_OPTIONS = [ + ("get", "g"), + ("post", "p"), + ("put", "u"), + ("head", "h"), + ("trace", "t"), + ("delete", "d"), + ("options", "o"), + ("edit raw", "e"), +] + def highlight_key(s, k): l = [] diff --git a/libmproxy/console/flowlist.py b/libmproxy/console/flowlist.py index c5cef061..8dfaba95 100644 --- a/libmproxy/console/flowlist.py +++ b/libmproxy/console/flowlist.py @@ -1,5 +1,6 @@ from __future__ import absolute_import import urwid +from netlib import http from . import common def _mkhelp(): @@ -16,6 +17,7 @@ def _mkhelp(): ("g", "copy flow to clipboard"), ("l", "set limit filter pattern"), ("L", "load saved flows"), + ("n", "creates a new request"), ("r", "replay request"), ("V", "revert changes to request"), ("w", "save flows "), @@ -245,6 +247,31 @@ class FlowListBox(urwid.ListBox): self.master = master urwid.ListBox.__init__(self, master.flow_list_walker) + def get_method_raw(self, k): + if k: + self.get_url(k) + + def get_method(self, k): + if k == "e": + self.master.prompt("Method:", "", self.get_method_raw) + else: + method = "" + for i in common.METHOD_OPTIONS: + if i[1] == k: + method = i[0].upper() + self.get_url(method) + + def get_url(self,method): + self.master.prompt("Url:", "http://www.example.com/", self.new_request, method) + + def new_request(self, url, method): + try: + scheme, host, port, path = http.parse_url(url) + f = self.master.add_request(method, scheme, host, port, path) + self.master.view_flow(f) + except ValueError: + self.master.statusbar.message("Invalid Url") + def keypress(self, size, key): key = common.shortcuts(key) if key == "A": @@ -262,6 +289,8 @@ class FlowListBox(urwid.ListBox): self.master.state.last_saveload, self.master.load_flows_callback ) + elif key == "n": + self.master.prompt_onekey("Method", common.METHOD_OPTIONS, self.get_method) elif key == "F": self.master.toggle_follow_flows() elif key == "W": diff --git a/libmproxy/console/flowview.py b/libmproxy/console/flowview.py index d5d41f7b..5c91512c 100644 --- a/libmproxy/console/flowview.py +++ b/libmproxy/console/flowview.py @@ -109,16 +109,6 @@ cache = CallbackCache() class FlowView(common.WWrap): REQ = 0 RESP = 1 - method_options = [ - ("get", "g"), - ("post", "p"), - ("put", "u"), - ("head", "h"), - ("trace", "t"), - ("delete", "d"), - ("options", "o"), - ("edit raw", "e"), - ] highlight_color = "focusfield" @@ -504,7 +494,7 @@ class FlowView(common.WWrap): if m == "e": self.master.prompt_edit("Method", self.flow.request.method, self.set_method_raw) else: - for i in self.method_options: + for i in common.METHOD_OPTIONS: if i[1] == m: self.flow.request.method = i[0].upper() self.master.refresh_flow(self.flow) @@ -599,7 +589,7 @@ class FlowView(common.WWrap): elif part == "u" and self.state.view_flow_mode == common.VIEW_FLOW_REQUEST: self.master.prompt_edit("URL", message.url, self.set_url) elif part == "m" and self.state.view_flow_mode == common.VIEW_FLOW_REQUEST: - self.master.prompt_onekey("Method", self.method_options, self.edit_method) + self.master.prompt_onekey("Method", common.METHOD_OPTIONS, self.edit_method) elif part == "c" and self.state.view_flow_mode == common.VIEW_FLOW_RESPONSE: self.master.prompt_edit("Code", str(message.code), self.set_resp_code) elif part == "m" and self.state.view_flow_mode == common.VIEW_FLOW_RESPONSE: diff --git a/libmproxy/flow.py b/libmproxy/flow.py index 49ec5a0b..d96b9b8c 100644 --- a/libmproxy/flow.py +++ b/libmproxy/flow.py @@ -763,6 +763,15 @@ class FlowMaster(controller.Master): def duplicate_flow(self, f): return self.load_flow(f.copy()) + def add_request(self, method, scheme, host, port, path): + f = http.HTTPFlow(None,None); + headers = ODictCaseless() + + req = http.HTTPRequest("relative", method, scheme, host, port, path, (1, 1), headers, None, + None, None, None) + f.request = req + return self.load_flow(f) + def load_flow(self, f): """ Loads a flow, and returns a new flow object. -- cgit v1.2.3