mirror of
https://github.com/Grasscutters/mitmproxy.git
synced 2024-11-26 18:18:25 +00:00
commit
bd6c3f64c1
@ -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 = []
|
||||
|
@ -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", "create a new request"),
|
||||
("r", "replay request"),
|
||||
("V", "revert changes to request"),
|
||||
("w", "save flows "),
|
||||
@ -245,6 +247,32 @@ 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):
|
||||
parts = http.parse_url(str(url))
|
||||
if not parts:
|
||||
self.master.statusbar.message("Invalid Url")
|
||||
return
|
||||
scheme, host, port, path = parts
|
||||
f = self.master.create_request(method, scheme, host, port, path)
|
||||
self.master.view_flow(f)
|
||||
|
||||
def keypress(self, size, key):
|
||||
key = common.shortcuts(key)
|
||||
if key == "A":
|
||||
@ -262,6 +290,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":
|
||||
|
@ -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:
|
||||
|
@ -8,12 +8,13 @@ import Cookie
|
||||
import cookielib
|
||||
import os
|
||||
import re
|
||||
from netlib import odict, wsgi
|
||||
from netlib import odict, wsgi, tcp
|
||||
import netlib.http
|
||||
from . import controller, protocol, tnetstring, filt, script, version
|
||||
from .onboarding import app
|
||||
from .protocol import http, handle
|
||||
from .proxy.config import HostMatcher
|
||||
from .proxy.connection import ClientConnection, ServerConnection
|
||||
import urlparse
|
||||
|
||||
ODict = odict.ODict
|
||||
@ -763,6 +764,31 @@ class FlowMaster(controller.Master):
|
||||
def duplicate_flow(self, f):
|
||||
return self.load_flow(f.copy())
|
||||
|
||||
def create_request(self, method, scheme, host, port, path):
|
||||
"""
|
||||
this method creates a new artificial and minimalist request also adds it to flowlist
|
||||
"""
|
||||
c = ClientConnection.from_state(dict(
|
||||
address=dict(address=(host, port), use_ipv6=False),
|
||||
clientcert=None
|
||||
))
|
||||
|
||||
s = ServerConnection.from_state(dict(
|
||||
address=dict(address=(host, port), use_ipv6=False),
|
||||
state=[],
|
||||
source_address=None, #source_address=dict(address=(host, port), use_ipv6=False),
|
||||
cert=None,
|
||||
sni=host,
|
||||
ssl_established=True
|
||||
))
|
||||
f = http.HTTPFlow(c,s);
|
||||
headers = ODictCaseless()
|
||||
|
||||
req = http.HTTPRequest("absolute", 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.
|
||||
|
@ -1459,7 +1459,6 @@ class RequestReplayThread(threading.Thread):
|
||||
if r.scheme == "https":
|
||||
server.establish_ssl(self.config.clientcerts, sni=self.flow.server_conn.sni)
|
||||
r.form_out = "relative"
|
||||
|
||||
server.send(r.assemble())
|
||||
self.flow.server_conn = server
|
||||
self.flow.response = HTTPResponse.from_stream(server.rfile, r.method,
|
||||
|
Loading…
Reference in New Issue
Block a user