2012-02-08 19:14:00 +00:00
|
|
|
import os
|
2012-02-07 03:39:37 +00:00
|
|
|
import urwid
|
|
|
|
import common
|
2012-02-08 03:43:11 +00:00
|
|
|
from .. import utils, encoding, flow
|
2012-02-07 03:39:37 +00:00
|
|
|
|
2012-02-08 08:47:39 +00:00
|
|
|
def _mkhelp():
|
|
|
|
text = []
|
|
|
|
keys = [
|
2012-02-08 09:28:15 +00:00
|
|
|
("A", "accept all intercepted connections"),
|
|
|
|
("a", "accept this intercepted connection"),
|
2012-02-08 08:47:39 +00:00
|
|
|
("b", "save request/response body"),
|
2012-02-09 04:00:37 +00:00
|
|
|
("d", "delete flow"),
|
2012-02-08 08:47:39 +00:00
|
|
|
("e", "edit request/response"),
|
2012-02-08 09:28:15 +00:00
|
|
|
("m", "change body display mode"),
|
|
|
|
(None,
|
|
|
|
common.highlight_key("raw", "r") +
|
|
|
|
[("text", ": raw data")]
|
|
|
|
),
|
|
|
|
(None,
|
|
|
|
common.highlight_key("pretty", "p") +
|
|
|
|
[("text", ": pretty-print XML, HTML and JSON")]
|
|
|
|
),
|
|
|
|
(None,
|
|
|
|
common.highlight_key("hex", "h") +
|
|
|
|
[("text", ": hex dump")]
|
|
|
|
),
|
2012-02-08 08:47:39 +00:00
|
|
|
("p", "previous flow"),
|
2012-02-08 09:55:48 +00:00
|
|
|
("r", "replay request"),
|
2012-02-18 01:45:22 +00:00
|
|
|
("V", "revert changes to request"),
|
2012-02-08 08:47:39 +00:00
|
|
|
("v", "view body in external viewer"),
|
2012-02-08 09:55:48 +00:00
|
|
|
("w", "save all flows matching current limit"),
|
|
|
|
("W", "save this flow"),
|
2012-02-08 08:47:39 +00:00
|
|
|
("z", "encode/decode a request/response"),
|
|
|
|
("tab", "toggle request/response view"),
|
|
|
|
("space", "next flow"),
|
2012-02-08 09:28:15 +00:00
|
|
|
("|", "run script on this flow"),
|
2012-02-08 08:47:39 +00:00
|
|
|
]
|
|
|
|
text.extend(common.format_keyvals(keys, key="key", val="text", indent=4))
|
|
|
|
return text
|
|
|
|
help_context = _mkhelp()
|
|
|
|
|
|
|
|
|
2012-02-07 03:39:37 +00:00
|
|
|
VIEW_CUTOFF = 1024*100
|
|
|
|
|
|
|
|
class ConnectionViewHeader(common.WWrap):
|
|
|
|
def __init__(self, master, f):
|
|
|
|
self.master, self.flow = master, f
|
2012-02-17 22:11:59 +00:00
|
|
|
self.w = common.format_flow(f, False, extended=True, padding=0)
|
2012-02-07 03:39:37 +00:00
|
|
|
|
|
|
|
def refresh_connection(self, f):
|
|
|
|
if f == self.flow:
|
2012-02-17 22:11:59 +00:00
|
|
|
self.w = common.format_flow(f, False, extended=True, padding=0)
|
2012-02-07 03:39:37 +00:00
|
|
|
|
|
|
|
|
|
|
|
class CallbackCache:
|
|
|
|
@utils.LRUCache(20)
|
|
|
|
def callback(self, obj, method, *args, **kwargs):
|
|
|
|
return getattr(obj, method)(*args, **kwargs)
|
|
|
|
cache = CallbackCache()
|
|
|
|
|
|
|
|
|
|
|
|
class ConnectionView(common.WWrap):
|
|
|
|
REQ = 0
|
|
|
|
RESP = 1
|
2012-02-08 20:38:11 +00:00
|
|
|
method_options = [
|
2012-02-07 03:39:37 +00:00
|
|
|
("get", "g"),
|
|
|
|
("post", "p"),
|
|
|
|
("put", "u"),
|
|
|
|
("head", "h"),
|
|
|
|
("trace", "t"),
|
|
|
|
("delete", "d"),
|
|
|
|
("options", "o"),
|
2012-02-08 20:38:11 +00:00
|
|
|
("edit raw", "e"),
|
2012-02-07 03:39:37 +00:00
|
|
|
]
|
|
|
|
def __init__(self, master, state, flow):
|
|
|
|
self.master, self.state, self.flow = master, state, flow
|
|
|
|
if self.state.view_flow_mode == common.VIEW_FLOW_RESPONSE and flow.response:
|
|
|
|
self.view_response()
|
|
|
|
else:
|
|
|
|
self.view_request()
|
|
|
|
|
|
|
|
def _trailer(self, clen, txt):
|
|
|
|
rem = clen - VIEW_CUTOFF
|
|
|
|
if rem > 0:
|
|
|
|
txt.append(urwid.Text(""))
|
|
|
|
txt.append(
|
|
|
|
urwid.Text(
|
|
|
|
[
|
|
|
|
("highlight", "... %s of data not shown"%utils.pretty_size(rem))
|
|
|
|
]
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
def _view_conn_raw(self, content):
|
|
|
|
txt = []
|
|
|
|
for i in utils.cleanBin(content[:VIEW_CUTOFF]).splitlines():
|
|
|
|
txt.append(
|
|
|
|
urwid.Text(("text", i))
|
|
|
|
)
|
|
|
|
self._trailer(len(content), txt)
|
|
|
|
return txt
|
|
|
|
|
|
|
|
def _view_conn_binary(self, content):
|
|
|
|
txt = []
|
|
|
|
for offset, hexa, s in utils.hexdump(content[:VIEW_CUTOFF]):
|
|
|
|
txt.append(urwid.Text([
|
|
|
|
("offset", offset),
|
|
|
|
" ",
|
|
|
|
("text", hexa),
|
|
|
|
" ",
|
|
|
|
("text", s),
|
|
|
|
]))
|
|
|
|
self._trailer(len(content), txt)
|
|
|
|
return txt
|
|
|
|
|
|
|
|
def _view_conn_xmlish(self, content):
|
|
|
|
txt = []
|
|
|
|
for i in utils.pretty_xmlish(content[:VIEW_CUTOFF]):
|
|
|
|
txt.append(
|
|
|
|
urwid.Text(("text", i)),
|
|
|
|
)
|
|
|
|
self._trailer(len(content), txt)
|
|
|
|
return txt
|
|
|
|
|
|
|
|
def _view_conn_json(self, lines):
|
|
|
|
txt = []
|
|
|
|
sofar = 0
|
|
|
|
for i in lines:
|
|
|
|
sofar += len(i)
|
|
|
|
txt.append(
|
|
|
|
urwid.Text(("text", i)),
|
|
|
|
)
|
|
|
|
if sofar > VIEW_CUTOFF:
|
|
|
|
break
|
|
|
|
self._trailer(sum(len(i) for i in lines), txt)
|
|
|
|
return txt
|
|
|
|
|
|
|
|
def _view_conn_formdata(self, content, boundary):
|
|
|
|
rx = re.compile(r'\bname="([^"]+)"')
|
|
|
|
keys = []
|
|
|
|
vals = []
|
|
|
|
|
|
|
|
for i in content.split("--" + boundary):
|
|
|
|
parts = i.splitlines()
|
|
|
|
if len(parts) > 1 and parts[0][0:2] != "--":
|
|
|
|
match = rx.search(parts[1])
|
|
|
|
if match:
|
|
|
|
keys.append(match.group(1) + ":")
|
|
|
|
vals.append(utils.cleanBin(
|
|
|
|
"\n".join(parts[3+parts[2:].index(""):])
|
|
|
|
))
|
2012-02-11 05:23:07 +00:00
|
|
|
r = [
|
|
|
|
urwid.Text(("highlight", "Form data:\n")),
|
|
|
|
]
|
|
|
|
r.extend(common.format_keyvals(
|
2012-02-07 03:39:37 +00:00
|
|
|
zip(keys, vals),
|
|
|
|
key = "header",
|
|
|
|
val = "text"
|
2012-02-11 05:23:07 +00:00
|
|
|
))
|
|
|
|
return r
|
2012-02-07 03:39:37 +00:00
|
|
|
|
|
|
|
def _view_conn_urlencoded(self, lines):
|
2012-02-11 05:23:07 +00:00
|
|
|
return common.format_keyvals(
|
|
|
|
[(k+":", v) for (k, v) in lines],
|
|
|
|
key = "header",
|
|
|
|
val = "text"
|
|
|
|
)
|
|
|
|
|
2012-02-07 03:39:37 +00:00
|
|
|
|
|
|
|
def _find_pretty_view(self, content, hdrItems):
|
|
|
|
ctype = None
|
|
|
|
for i in hdrItems:
|
|
|
|
if i[0].lower() == "content-type":
|
|
|
|
ctype = i[1]
|
|
|
|
break
|
2012-02-10 01:27:39 +00:00
|
|
|
if ctype and flow.HDR_FORM_URLENCODED in ctype:
|
2012-02-07 03:39:37 +00:00
|
|
|
data = utils.urldecode(content)
|
|
|
|
if data:
|
2012-02-10 22:25:35 +00:00
|
|
|
return "URLEncoded form", self._view_conn_urlencoded(data)
|
2012-02-07 03:39:37 +00:00
|
|
|
if utils.isXML(content):
|
2012-02-10 22:25:35 +00:00
|
|
|
return "Indented XML-ish", self._view_conn_xmlish(content)
|
2012-02-07 03:39:37 +00:00
|
|
|
elif ctype and "application/json" in ctype:
|
|
|
|
lines = utils.pretty_json(content)
|
|
|
|
if lines:
|
2012-02-10 22:25:35 +00:00
|
|
|
return "JSON", self._view_conn_json(lines)
|
2012-02-07 03:39:37 +00:00
|
|
|
elif ctype and "multipart/form-data" in ctype:
|
|
|
|
boundary = ctype.split('boundary=')
|
|
|
|
if len(boundary) > 1:
|
2012-02-11 05:23:07 +00:00
|
|
|
return "Form data", self._view_conn_formdata(content, boundary[1].split(';')[0])
|
2012-02-10 22:25:35 +00:00
|
|
|
return "", self._view_conn_raw(content)
|
2012-02-07 03:39:37 +00:00
|
|
|
|
|
|
|
def _cached_conn_text(self, e, content, hdrItems, viewmode):
|
2012-02-11 05:23:07 +00:00
|
|
|
txt = common.format_keyvals(
|
2012-02-07 03:39:37 +00:00
|
|
|
[(h+":", v) for (h, v) in hdrItems],
|
|
|
|
key = "header",
|
|
|
|
val = "text"
|
|
|
|
)
|
|
|
|
if content:
|
2012-02-10 22:25:35 +00:00
|
|
|
msg = ""
|
2012-02-07 03:39:37 +00:00
|
|
|
if viewmode == common.VIEW_BODY_HEX:
|
2012-02-10 22:25:35 +00:00
|
|
|
body = self._view_conn_binary(content)
|
2012-02-07 03:39:37 +00:00
|
|
|
elif viewmode == common.VIEW_BODY_PRETTY:
|
2012-02-10 22:25:35 +00:00
|
|
|
emsg = ""
|
2012-02-07 03:39:37 +00:00
|
|
|
if e:
|
|
|
|
decoded = encoding.decode(e, content)
|
|
|
|
if decoded:
|
|
|
|
content = decoded
|
|
|
|
if e and e != "identity":
|
2012-02-10 22:25:35 +00:00
|
|
|
emsg = "[decoded %s]"%e
|
|
|
|
msg, body = self._find_pretty_view(content, hdrItems)
|
|
|
|
if emsg:
|
|
|
|
msg = emsg + " " + msg
|
2012-02-07 03:39:37 +00:00
|
|
|
else:
|
2012-02-10 22:25:35 +00:00
|
|
|
body = self._view_conn_raw(content)
|
|
|
|
|
|
|
|
title = urwid.AttrWrap(urwid.Columns([
|
|
|
|
urwid.Text(
|
|
|
|
[
|
|
|
|
("statusbar", msg),
|
|
|
|
]
|
|
|
|
),
|
|
|
|
urwid.Text(
|
|
|
|
[
|
|
|
|
" ",
|
|
|
|
('statusbar_text', "["),
|
|
|
|
('statusbar_key', "m"),
|
|
|
|
('statusbar_text', (":%s]"%common.BODY_VIEWS[self.master.state.view_body_mode])),
|
|
|
|
],
|
|
|
|
align="right"
|
|
|
|
),
|
|
|
|
]), "statusbar")
|
|
|
|
txt.append(title)
|
|
|
|
txt.extend(body)
|
2012-02-07 03:39:37 +00:00
|
|
|
return urwid.ListBox(txt)
|
|
|
|
|
|
|
|
def _tab(self, content, active):
|
|
|
|
if active:
|
|
|
|
attr = "heading"
|
|
|
|
else:
|
|
|
|
attr = "inactive"
|
|
|
|
p = urwid.Text(content)
|
|
|
|
p = urwid.Padding(p, align="left", width=("relative", 100))
|
|
|
|
p = urwid.AttrWrap(p, attr)
|
|
|
|
return p
|
|
|
|
|
|
|
|
def wrap_body(self, active, body):
|
|
|
|
parts = []
|
|
|
|
|
|
|
|
if self.flow.intercepting and not self.flow.request.acked:
|
|
|
|
qt = "Request (intercepted)"
|
|
|
|
else:
|
|
|
|
qt = "Request"
|
|
|
|
if active == common.VIEW_FLOW_REQUEST:
|
|
|
|
parts.append(self._tab(qt, True))
|
|
|
|
else:
|
|
|
|
parts.append(self._tab(qt, False))
|
|
|
|
|
2012-02-08 10:17:03 +00:00
|
|
|
if self.flow.intercepting and self.flow.response and not self.flow.response.acked:
|
2012-02-07 03:39:37 +00:00
|
|
|
st = "Response (intercepted)"
|
|
|
|
else:
|
|
|
|
st = "Response"
|
|
|
|
if active == common.VIEW_FLOW_RESPONSE:
|
|
|
|
parts.append(self._tab(st, True))
|
|
|
|
else:
|
|
|
|
parts.append(self._tab(st, False))
|
|
|
|
|
|
|
|
h = urwid.Columns(parts, dividechars=1)
|
|
|
|
f = urwid.Frame(
|
|
|
|
body,
|
|
|
|
header=h
|
|
|
|
)
|
|
|
|
return f
|
|
|
|
|
|
|
|
def _conn_text(self, conn, viewmode):
|
|
|
|
e = conn.headers["content-encoding"]
|
|
|
|
e = e[0] if e else None
|
|
|
|
return cache.callback(
|
|
|
|
self, "_cached_conn_text",
|
|
|
|
e,
|
|
|
|
conn.content,
|
|
|
|
tuple(tuple(i) for i in conn.headers.lst),
|
|
|
|
viewmode
|
|
|
|
)
|
|
|
|
|
|
|
|
def view_request(self):
|
|
|
|
self.state.view_flow_mode = common.VIEW_FLOW_REQUEST
|
|
|
|
self.master.statusbar.update("Calculating view...")
|
|
|
|
body = self._conn_text(
|
|
|
|
self.flow.request,
|
|
|
|
self.state.view_body_mode
|
|
|
|
)
|
|
|
|
self.w = self.wrap_body(common.VIEW_FLOW_REQUEST, body)
|
|
|
|
self.master.statusbar.update("")
|
|
|
|
|
|
|
|
def view_response(self):
|
|
|
|
self.state.view_flow_mode = common.VIEW_FLOW_RESPONSE
|
|
|
|
self.master.statusbar.update("Calculating view...")
|
|
|
|
if self.flow.response:
|
|
|
|
body = self._conn_text(
|
|
|
|
self.flow.response,
|
|
|
|
self.state.view_body_mode
|
|
|
|
)
|
|
|
|
else:
|
|
|
|
body = urwid.ListBox(
|
|
|
|
[
|
|
|
|
urwid.Text(""),
|
|
|
|
urwid.Text(
|
|
|
|
[
|
|
|
|
("highlight", "No response. Press "),
|
|
|
|
("key", "e"),
|
|
|
|
("highlight", " and edit any aspect to add one."),
|
|
|
|
]
|
|
|
|
)
|
|
|
|
]
|
|
|
|
)
|
|
|
|
self.w = self.wrap_body(common.VIEW_FLOW_RESPONSE, body)
|
|
|
|
self.master.statusbar.update("")
|
|
|
|
|
|
|
|
def refresh_connection(self, c=None):
|
|
|
|
if c == self.flow:
|
|
|
|
if self.state.view_flow_mode == common.VIEW_FLOW_RESPONSE and self.flow.response:
|
|
|
|
self.view_response()
|
|
|
|
else:
|
|
|
|
self.view_request()
|
|
|
|
|
2012-02-08 20:38:11 +00:00
|
|
|
def set_method_raw(self, m):
|
|
|
|
if m:
|
|
|
|
self.flow.request.method = m
|
|
|
|
self.master.refresh_connection(self.flow)
|
|
|
|
|
2012-02-07 03:39:37 +00:00
|
|
|
def edit_method(self, m):
|
2012-02-08 20:38:11 +00:00
|
|
|
if m == "e":
|
|
|
|
self.master.prompt_edit("Method", self.flow.request.method, self.set_method_raw)
|
|
|
|
else:
|
|
|
|
for i in self.method_options:
|
|
|
|
if i[1] == m:
|
|
|
|
self.flow.request.method = i[0].upper()
|
|
|
|
self.master.refresh_connection(self.flow)
|
2012-02-07 03:39:37 +00:00
|
|
|
|
|
|
|
def save_body(self, path):
|
|
|
|
if not path:
|
|
|
|
return
|
|
|
|
self.state.last_saveload = path
|
|
|
|
if self.state.view_flow_mode == common.VIEW_FLOW_REQUEST:
|
|
|
|
c = self.flow.request
|
|
|
|
else:
|
|
|
|
c = self.flow.response
|
|
|
|
path = os.path.expanduser(path)
|
|
|
|
try:
|
|
|
|
f = file(path, "wb")
|
|
|
|
f.write(str(c.content))
|
|
|
|
f.close()
|
|
|
|
except IOError, v:
|
|
|
|
self.master.statusbar.message(v.strerror)
|
|
|
|
|
|
|
|
def set_url(self, url):
|
|
|
|
request = self.flow.request
|
|
|
|
if not request.set_url(str(url)):
|
|
|
|
return "Invalid URL."
|
|
|
|
self.master.refresh_connection(self.flow)
|
|
|
|
|
|
|
|
def set_resp_code(self, code):
|
|
|
|
response = self.flow.response
|
|
|
|
try:
|
|
|
|
response.code = int(code)
|
|
|
|
except ValueError:
|
|
|
|
return None
|
|
|
|
import BaseHTTPServer
|
|
|
|
if BaseHTTPServer.BaseHTTPRequestHandler.responses.has_key(int(code)):
|
|
|
|
response.msg = BaseHTTPServer.BaseHTTPRequestHandler.responses[int(code)][0]
|
|
|
|
self.master.refresh_connection(self.flow)
|
|
|
|
|
|
|
|
def set_resp_msg(self, msg):
|
|
|
|
response = self.flow.response
|
|
|
|
response.msg = msg
|
|
|
|
self.master.refresh_connection(self.flow)
|
|
|
|
|
2012-02-08 03:43:11 +00:00
|
|
|
def set_headers(self, lst, conn):
|
|
|
|
conn.headers = flow.Headers(lst)
|
|
|
|
|
2012-02-09 03:47:32 +00:00
|
|
|
def set_query(self, lst, conn):
|
|
|
|
conn.set_query(lst)
|
|
|
|
|
2012-02-10 01:35:23 +00:00
|
|
|
def set_form(self, lst, conn):
|
|
|
|
conn.set_form_urlencoded(lst)
|
|
|
|
|
2012-02-07 03:39:37 +00:00
|
|
|
def edit(self, part):
|
|
|
|
if self.state.view_flow_mode == common.VIEW_FLOW_REQUEST:
|
|
|
|
conn = self.flow.request
|
|
|
|
else:
|
|
|
|
if not self.flow.response:
|
|
|
|
self.flow.response = flow.Response(self.flow.request, 200, "OK", flow.Headers(), "")
|
|
|
|
conn = self.flow.response
|
|
|
|
|
|
|
|
self.flow.backup()
|
2012-02-09 03:40:31 +00:00
|
|
|
if part == "r":
|
2012-02-08 05:25:00 +00:00
|
|
|
c = self.master.spawn_editor(conn.content or "")
|
2012-02-07 03:39:37 +00:00
|
|
|
conn.content = c.rstrip("\n")
|
2012-02-10 01:35:23 +00:00
|
|
|
elif part == "f":
|
|
|
|
self.master.view_kveditor("Editing form", conn.get_form_urlencoded(), self.set_form, conn)
|
2012-02-07 03:39:37 +00:00
|
|
|
elif part == "h":
|
2012-02-08 03:43:11 +00:00
|
|
|
self.master.view_kveditor("Editing headers", conn.headers.lst, self.set_headers, conn)
|
2012-02-09 03:47:32 +00:00
|
|
|
elif part == "q":
|
|
|
|
self.master.view_kveditor("Editing query", conn.get_query(), self.set_query, conn)
|
2012-02-07 03:39:37 +00:00
|
|
|
elif part == "u" and self.state.view_flow_mode == common.VIEW_FLOW_REQUEST:
|
|
|
|
self.master.prompt_edit("URL", conn.get_url(), self.set_url)
|
|
|
|
elif part == "m" and self.state.view_flow_mode == common.VIEW_FLOW_REQUEST:
|
2012-02-08 20:38:11 +00:00
|
|
|
self.master.prompt_onekey("Method", self.method_options, self.edit_method)
|
2012-02-07 03:39:37 +00:00
|
|
|
elif part == "c" and self.state.view_flow_mode == common.VIEW_FLOW_RESPONSE:
|
|
|
|
self.master.prompt_edit("Code", str(conn.code), self.set_resp_code)
|
|
|
|
elif part == "m" and self.state.view_flow_mode == common.VIEW_FLOW_RESPONSE:
|
|
|
|
self.master.prompt_edit("Message", conn.msg, self.set_resp_msg)
|
|
|
|
self.master.refresh_connection(self.flow)
|
|
|
|
|
2012-02-08 01:07:17 +00:00
|
|
|
def _view_nextprev_flow(self, np, flow):
|
|
|
|
try:
|
|
|
|
idx = self.state.view.index(flow)
|
|
|
|
except IndexError:
|
|
|
|
return
|
|
|
|
if np == "next":
|
|
|
|
new_flow, new_idx = self.state.get_next(idx)
|
|
|
|
else:
|
|
|
|
new_flow, new_idx = self.state.get_prev(idx)
|
|
|
|
if new_idx is None:
|
|
|
|
return
|
|
|
|
self.master.view_flow(new_flow)
|
|
|
|
|
|
|
|
def view_next_flow(self, flow):
|
|
|
|
return self._view_nextprev_flow("next", flow)
|
|
|
|
|
|
|
|
def view_prev_flow(self, flow):
|
|
|
|
return self._view_nextprev_flow("prev", flow)
|
|
|
|
|
2012-02-07 03:39:37 +00:00
|
|
|
def keypress(self, size, key):
|
|
|
|
if key == " ":
|
2012-02-08 01:07:17 +00:00
|
|
|
self.view_next_flow(self.flow)
|
2012-02-07 03:39:37 +00:00
|
|
|
return key
|
|
|
|
|
|
|
|
key = common.shortcuts(key)
|
|
|
|
if self.state.view_flow_mode == common.VIEW_FLOW_REQUEST:
|
|
|
|
conn = self.flow.request
|
|
|
|
else:
|
|
|
|
conn = self.flow.response
|
|
|
|
|
|
|
|
if key == "q":
|
|
|
|
self.master.view_connlist()
|
|
|
|
key = None
|
|
|
|
elif key == "tab":
|
|
|
|
if self.state.view_flow_mode == common.VIEW_FLOW_REQUEST:
|
|
|
|
self.view_response()
|
|
|
|
else:
|
|
|
|
self.view_request()
|
|
|
|
elif key in ("up", "down", "page up", "page down"):
|
|
|
|
# Why doesn't this just work??
|
2012-02-10 22:31:57 +00:00
|
|
|
self.w.keypress(size, key)
|
2012-02-07 03:39:37 +00:00
|
|
|
elif key == "a":
|
|
|
|
self.flow.accept_intercept()
|
|
|
|
self.master.view_flow(self.flow)
|
|
|
|
elif key == "A":
|
|
|
|
self.master.accept_all()
|
|
|
|
self.master.view_flow(self.flow)
|
2012-02-09 04:00:37 +00:00
|
|
|
elif key == "d":
|
|
|
|
if self.state.flow_count() == 1:
|
|
|
|
self.master.view_connlist()
|
|
|
|
elif self.state.view.index(self.flow) == len(self.state.view)-1:
|
|
|
|
self.view_prev_flow(self.flow)
|
|
|
|
else:
|
|
|
|
self.view_next_flow(self.flow)
|
|
|
|
f = self.flow
|
|
|
|
f.kill(self.master)
|
|
|
|
self.state.delete_flow(f)
|
2012-02-07 03:39:37 +00:00
|
|
|
elif key == "e":
|
|
|
|
if self.state.view_flow_mode == common.VIEW_FLOW_REQUEST:
|
|
|
|
self.master.prompt_onekey(
|
|
|
|
"Edit request",
|
|
|
|
(
|
2012-02-09 03:47:32 +00:00
|
|
|
("query", "q"),
|
2012-02-10 01:35:23 +00:00
|
|
|
("form", "f"),
|
2012-02-09 03:47:32 +00:00
|
|
|
("url", "u"),
|
2012-02-07 03:39:37 +00:00
|
|
|
("header", "h"),
|
2012-02-09 03:40:31 +00:00
|
|
|
("raw body", "r"),
|
2012-02-07 03:39:37 +00:00
|
|
|
("method", "m"),
|
|
|
|
),
|
|
|
|
self.edit
|
|
|
|
)
|
|
|
|
else:
|
|
|
|
self.master.prompt_onekey(
|
|
|
|
"Edit response",
|
|
|
|
(
|
|
|
|
("code", "c"),
|
|
|
|
("message", "m"),
|
|
|
|
("header", "h"),
|
2012-02-09 03:40:31 +00:00
|
|
|
("raw body", "r"),
|
2012-02-07 03:39:37 +00:00
|
|
|
),
|
|
|
|
self.edit
|
|
|
|
)
|
|
|
|
key = None
|
2012-02-08 09:28:15 +00:00
|
|
|
elif key == "m":
|
|
|
|
self.master.prompt_onekey(
|
|
|
|
"View",
|
|
|
|
(
|
|
|
|
("raw", "r"),
|
|
|
|
("pretty", "p"),
|
|
|
|
("hex", "h"),
|
|
|
|
),
|
|
|
|
self.master.changeview
|
|
|
|
)
|
|
|
|
key = None
|
2012-02-07 03:39:37 +00:00
|
|
|
elif key == "p":
|
2012-02-08 01:07:17 +00:00
|
|
|
self.view_prev_flow(self.flow)
|
2012-02-07 03:39:37 +00:00
|
|
|
elif key == "r":
|
|
|
|
r = self.master.replay_request(self.flow)
|
|
|
|
if r:
|
|
|
|
self.master.statusbar.message(r)
|
|
|
|
self.master.refresh_connection(self.flow)
|
2012-02-18 01:45:22 +00:00
|
|
|
elif key == "V":
|
2012-02-07 03:39:37 +00:00
|
|
|
self.state.revert(self.flow)
|
|
|
|
self.master.refresh_connection(self.flow)
|
|
|
|
elif key == "W":
|
|
|
|
self.master.path_prompt(
|
|
|
|
"Save this flow: ",
|
|
|
|
self.state.last_saveload,
|
|
|
|
self.master.save_one_flow,
|
|
|
|
self.flow
|
|
|
|
)
|
|
|
|
elif key == "v":
|
|
|
|
if conn and conn.content:
|
|
|
|
t = conn.headers["content-type"] or [None]
|
|
|
|
t = t[0]
|
|
|
|
self.master.spawn_external_viewer(conn.content, t)
|
|
|
|
elif key == "b":
|
|
|
|
if conn:
|
|
|
|
if self.state.view_flow_mode == common.VIEW_FLOW_REQUEST:
|
|
|
|
self.master.path_prompt(
|
|
|
|
"Save request body: ",
|
|
|
|
self.state.last_saveload,
|
|
|
|
self.save_body
|
|
|
|
)
|
|
|
|
else:
|
|
|
|
self.master.path_prompt(
|
|
|
|
"Save response body: ",
|
|
|
|
self.state.last_saveload,
|
|
|
|
self.save_body
|
|
|
|
)
|
|
|
|
elif key == "|":
|
|
|
|
self.master.path_prompt(
|
|
|
|
"Send flow to script: ", self.state.last_script,
|
|
|
|
self.master.run_script_once, self.flow
|
|
|
|
)
|
|
|
|
elif key == "z":
|
|
|
|
if conn:
|
|
|
|
e = conn.headers["content-encoding"] or ["identity"]
|
|
|
|
if e[0] != "identity":
|
|
|
|
conn.decode()
|
|
|
|
else:
|
|
|
|
self.master.prompt_onekey(
|
|
|
|
"Select encoding: ",
|
|
|
|
(
|
|
|
|
("gzip", "z"),
|
|
|
|
("deflate", "d"),
|
|
|
|
),
|
|
|
|
self.encode_callback,
|
|
|
|
conn
|
|
|
|
)
|
|
|
|
self.master.refresh_connection(self.flow)
|
2012-02-08 09:28:15 +00:00
|
|
|
else:
|
|
|
|
return key
|
2012-02-07 03:39:37 +00:00
|
|
|
|
|
|
|
def encode_callback(self, key, conn):
|
|
|
|
encoding_map = {
|
|
|
|
"z": "gzip",
|
|
|
|
"d": "deflate",
|
|
|
|
}
|
|
|
|
conn.encode(encoding_map[key])
|
|
|
|
self.master.refresh_connection(self.flow)
|