mirror of
https://github.com/Grasscutters/mitmproxy.git
synced 2024-11-26 02:10:59 +00:00
Basix XML/HTML pretty-printing in flow viewer.
This commit is contained in:
parent
96e714a74c
commit
93ef691bad
@ -144,6 +144,9 @@ class ConnectionViewHeader(WWrap):
|
||||
if f == self.flow:
|
||||
self.w = urwid.Text(f.get_text(nofocus=True, padding=0))
|
||||
|
||||
VIEW_NORMAL = 0
|
||||
VIEW_BINARY = 1
|
||||
VIEW_PRETTY = 2
|
||||
|
||||
class ConnectionView(WWrap):
|
||||
REQ = 0
|
||||
@ -160,7 +163,6 @@ class ConnectionView(WWrap):
|
||||
]
|
||||
def __init__(self, master, state, flow):
|
||||
self.master, self.state, self.flow = master, state, flow
|
||||
self.binary = False
|
||||
self.view_request()
|
||||
|
||||
def _tab(self, content, active):
|
||||
@ -202,6 +204,35 @@ class ConnectionView(WWrap):
|
||||
)
|
||||
return f
|
||||
|
||||
def _view_normal(self, conn, txt):
|
||||
for i in conn.content.splitlines():
|
||||
txt.append(
|
||||
("text", i),
|
||||
)
|
||||
txt.append(
|
||||
("text", "\n"),
|
||||
)
|
||||
|
||||
def _view_binary(self, conn, txt):
|
||||
for offset, hex, s in utils.hexdump(conn.content):
|
||||
txt.extend([
|
||||
("offset", offset),
|
||||
" ",
|
||||
("text", hex),
|
||||
" ",
|
||||
("text", s),
|
||||
"\n"
|
||||
])
|
||||
|
||||
def _view_pretty(self, conn, txt):
|
||||
for i in utils.prettybody(conn.content):
|
||||
txt.append(
|
||||
("text", i),
|
||||
)
|
||||
txt.append(
|
||||
("text", "\n"),
|
||||
)
|
||||
|
||||
def _conn_text(self, conn):
|
||||
txt = []
|
||||
txt.extend(
|
||||
@ -213,24 +244,14 @@ class ConnectionView(WWrap):
|
||||
)
|
||||
txt.append("\n\n")
|
||||
if conn.content:
|
||||
if self.binary or utils.isBin(conn.content):
|
||||
for offset, hex, s in utils.hexdump(conn.content):
|
||||
txt.extend([
|
||||
("offset", offset),
|
||||
" ",
|
||||
("text", hex),
|
||||
" ",
|
||||
("text", s),
|
||||
"\n"
|
||||
])
|
||||
if utils.isBin(conn.content):
|
||||
self._view_binary(conn, txt)
|
||||
elif self.state.viewmode == VIEW_BINARY:
|
||||
self._view_binary(conn, txt)
|
||||
elif self.state.viewmode == VIEW_PRETTY:
|
||||
self._view_pretty(conn, txt)
|
||||
else:
|
||||
for i in conn.content.splitlines():
|
||||
txt.append(
|
||||
("text", i),
|
||||
)
|
||||
txt.append(
|
||||
("text", "\n"),
|
||||
)
|
||||
self._view_normal(conn, txt)
|
||||
return urwid.ListBox([urwid.Text(txt)])
|
||||
|
||||
def view_request(self):
|
||||
@ -337,7 +358,13 @@ class ConnectionView(WWrap):
|
||||
self.master.accept_all()
|
||||
self.master.view_connection(self.flow)
|
||||
elif key == "b":
|
||||
self.binary = not self.binary
|
||||
self.state.viewmode = VIEW_BINARY
|
||||
self.master.refresh_connection(self.flow)
|
||||
elif key == "n":
|
||||
self.state.viewmode = VIEW_NORMAL
|
||||
self.master.refresh_connection(self.flow)
|
||||
elif key == "p":
|
||||
self.state.viewmode = VIEW_PRETTY
|
||||
self.master.refresh_connection(self.flow)
|
||||
elif key == "e":
|
||||
if self.viewing == self.REQ:
|
||||
@ -595,6 +622,7 @@ class ConsoleState(flow.State):
|
||||
flow.State.__init__(self)
|
||||
self.focus = None
|
||||
self.beep = None
|
||||
self.viewmode = VIEW_NORMAL
|
||||
|
||||
def add_browserconnect(self, f):
|
||||
flow.State.add_browserconnect(self, f)
|
||||
@ -830,7 +858,10 @@ class ConsoleMaster(controller.Master):
|
||||
|
||||
text.extend([("head", "\n\nConnection view keys:\n")])
|
||||
keys = [
|
||||
("b", "toggle hexdump view"),
|
||||
("b", "view hexdump"),
|
||||
("n", "view normal"),
|
||||
("p", "view prettyprint"),
|
||||
("", ""),
|
||||
("e", "edit response/request"),
|
||||
("s", "save this flow"),
|
||||
("v", "view contents in external viewer"),
|
||||
|
2014
libmproxy/contrib/BeautifulSoup.py
Normal file
2014
libmproxy/contrib/BeautifulSoup.py
Normal file
File diff suppressed because it is too large
Load Diff
@ -14,6 +14,7 @@
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
import re, os, subprocess
|
||||
from contrib import BeautifulSoup
|
||||
|
||||
def isBin(s):
|
||||
"""
|
||||
@ -41,6 +42,15 @@ def cleanBin(s):
|
||||
return "".join(parts)
|
||||
|
||||
|
||||
def prettybody(s):
|
||||
"""
|
||||
Return a list of pretty-printed lines.
|
||||
"""
|
||||
s = BeautifulSoup.BeautifulStoneSoup(s)
|
||||
s = s.prettify()
|
||||
return s.split("\n")
|
||||
|
||||
|
||||
def hexdump(s):
|
||||
"""
|
||||
Returns a set of typles:
|
||||
|
@ -223,6 +223,12 @@ class umake_bogus_cert(libpry.AutoTree):
|
||||
assert "CERTIFICATE" in d
|
||||
|
||||
|
||||
class uprettybody(libpry.AutoTree):
|
||||
def test_all(self):
|
||||
s = "<html><p></p></html>"
|
||||
assert utils.prettybody(s)
|
||||
|
||||
|
||||
tests = [
|
||||
umake_bogus_cert(),
|
||||
uisBin(),
|
||||
@ -233,4 +239,5 @@ tests = [
|
||||
uMultiDict(),
|
||||
uHeaders(),
|
||||
uData(),
|
||||
uprettybody(),
|
||||
]
|
||||
|
11
todo
11
todo
@ -1,20 +1,21 @@
|
||||
|
||||
Future:
|
||||
Futures:
|
||||
|
||||
- Strings view.
|
||||
- Field parsing and editing.
|
||||
- Timestamps
|
||||
|
||||
- Strings view for binary responses.
|
||||
- Post and URL field parsing and editing.
|
||||
- On-the-fly generation of keys, signed with a CA
|
||||
- Pass-through fast-track for things that don't match filter?
|
||||
- Reading contents from file
|
||||
- Shortcut for viewing in pager
|
||||
- Serializing and de-serializing requests and responses.
|
||||
- Use real non-blocking input handling to minimize cpu load.
|
||||
- Upstream proxies.
|
||||
- mitmdump
|
||||
- Filters
|
||||
- Sticky cookies
|
||||
- Pipe to script
|
||||
- After we add serialization of flows, command-line replay
|
||||
- Command-line replay or serialized flows
|
||||
|
||||
Bugs:
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user