Version 0.2.5
This commit is contained in:
parent
0b6a63ddbb
commit
1acaeccf5e
14 changed files with 119 additions and 11 deletions
|
@ -99,6 +99,8 @@ class CommServer(LineReceiver):
|
|||
def action_submit_request(self, data):
|
||||
message = base64.b64decode(data['full_message'])
|
||||
req = yield Request.submit_new(data['host'], data['port'], data['is_ssl'], message)
|
||||
if 'tags' in data:
|
||||
req.tags = data['tags']
|
||||
yield req.async_deep_save()
|
||||
|
||||
retdata = {}
|
||||
|
|
|
@ -262,7 +262,7 @@ class ProxyCmd(cmd2.Cmd):
|
|||
"""
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
self.prompt = 'pappy> '
|
||||
self.prompt = 'pappy' + Colors.YELLOW + '> ' + Colors.ENDC
|
||||
self.debug = True
|
||||
|
||||
self._cmds = {}
|
||||
|
|
|
@ -803,7 +803,17 @@ class HTTPMessage(object):
|
|||
stripped = True
|
||||
elif key.lower() == 'content-length':
|
||||
# We use our own content length
|
||||
self._data_obj = LengthData(int(val))
|
||||
if self._data_obj and self._data_obj.complete:
|
||||
# We're regenerating or something so we want to base this header
|
||||
# off our existing body
|
||||
val = self._data_obj.body
|
||||
self._data_obj = LengthData(len(val))
|
||||
if len(val) > 0:
|
||||
self._data_obj.add_data(val)
|
||||
self._encoding_type = ENCODE_NONE
|
||||
self.complete = True
|
||||
else:
|
||||
self._data_obj = LengthData(int(val))
|
||||
|
||||
return (not stripped)
|
||||
|
||||
|
@ -1972,8 +1982,10 @@ class Request(HTTPMessage):
|
|||
"""
|
||||
from .proxy import ProxyClientFactory, get_next_connection_id, ClientTLSContext
|
||||
|
||||
new_obj = Request(full_request)
|
||||
factory = ProxyClientFactory(new_obj, save_all=False)
|
||||
new_req = Request(full_request)
|
||||
new_req.is_ssl = is_ssl
|
||||
new_req.port = port
|
||||
factory = ProxyClientFactory(new_req, save_all=False)
|
||||
factory.connection_id = get_next_connection_id()
|
||||
if is_ssl:
|
||||
reactor.connectSSL(host, port, factory, ClientTLSContext())
|
||||
|
|
|
@ -109,7 +109,7 @@ def active_intercepting_macros():
|
|||
Returns a list of the active intercepting macro objects. Modifying
|
||||
this list will not affect which macros are active.
|
||||
"""
|
||||
return pappyproxy.pappy.server_factory.intercepting_macros[:]
|
||||
return [v for k, v in pappyproxy.pappy.server_factory.intercepting_macros.iteritems() ]
|
||||
|
||||
def in_memory_reqs():
|
||||
"""
|
||||
|
|
|
@ -54,6 +54,8 @@ def _code_helper(line, func, copy=True):
|
|||
args = shlex.split(line)
|
||||
if not args:
|
||||
s = clipboard.paste()
|
||||
print 'Will decode:'
|
||||
print printable_data(s)
|
||||
s = func(s)
|
||||
if copy:
|
||||
try:
|
||||
|
|
|
@ -124,7 +124,7 @@ def list_int_macros(line):
|
|||
running = []
|
||||
not_running = []
|
||||
for macro in loaded_int_macros:
|
||||
if macro.name in active_intercepting_macros():
|
||||
if macro.name in [m.name for m in active_intercepting_macros()]:
|
||||
running.append(macro)
|
||||
else:
|
||||
not_running.append(macro)
|
||||
|
|
|
@ -212,7 +212,11 @@ def intercept(line):
|
|||
editor = 'vi'
|
||||
if 'EDITOR' in os.environ:
|
||||
editor = os.environ['EDITOR']
|
||||
subprocess.call([editor, to_edit])
|
||||
additional_args = []
|
||||
if editor == 'vim':
|
||||
# prevent adding additional newline
|
||||
additional_args.append('-b')
|
||||
subprocess.call([editor, to_edit] + additional_args)
|
||||
stdscr.clear()
|
||||
deferred.callback(None)
|
||||
finally:
|
||||
|
|
|
@ -1,6 +1,9 @@
|
|||
import crochet
|
||||
import datetime
|
||||
import json
|
||||
import pappyproxy
|
||||
import pygments
|
||||
import pprint
|
||||
import shlex
|
||||
|
||||
from pappyproxy.console import load_reqlist, print_table, print_request_rows, get_req_data_row
|
||||
|
@ -9,6 +12,8 @@ from pappyproxy.http import Request
|
|||
from twisted.internet import defer
|
||||
from pappyproxy.plugin import main_context_ids
|
||||
from pappyproxy.colors import Colors, Styles, verb_color, scode_color, path_formatter, host_color
|
||||
from pygments.formatters import TerminalFormatter
|
||||
from pygments.lexers.data import JsonLexer
|
||||
|
||||
###################
|
||||
## Helper functions
|
||||
|
@ -91,6 +96,17 @@ def print_tree(tree):
|
|||
# Prints a tree. Takes in a sorted list of path tuples
|
||||
_print_tree_helper(tree, 0, [])
|
||||
|
||||
def pretty_print_body(fmt, body):
|
||||
if fmt.lower() == 'json':
|
||||
try:
|
||||
d = json.loads(body.strip())
|
||||
except:
|
||||
raise PappyException('Body could not be parsed as JSON')
|
||||
s = json.dumps(d, indent=4, sort_keys=True)
|
||||
print pygments.highlight(s, JsonLexer(), TerminalFormatter())
|
||||
else:
|
||||
raise PappyException('%s is not a valid format' % fmt)
|
||||
|
||||
def _get_tree_prefix(depth, print_bars, last):
|
||||
if depth == 0:
|
||||
return u''
|
||||
|
@ -247,6 +263,22 @@ def view_request_bytes(line):
|
|||
if len(reqs) > 1:
|
||||
print '-'*30
|
||||
print ''
|
||||
|
||||
@crochet.wait_for(timeout=None)
|
||||
@defer.inlineCallbacks
|
||||
def pretty_print_request(line):
|
||||
"""
|
||||
Print the body of the request pretty printed.
|
||||
Usage: pretty_print_request <format> <reqid(s)>
|
||||
"""
|
||||
args = shlex.split(line)
|
||||
if len(args) < 2:
|
||||
raise PappyException("Usage: pretty_print_request <format> <reqid(s)>")
|
||||
reqids = args[1]
|
||||
|
||||
reqs = yield load_reqlist(reqids)
|
||||
for req in reqs:
|
||||
pretty_print_body(args[0], req.body)
|
||||
|
||||
@crochet.wait_for(timeout=None)
|
||||
@defer.inlineCallbacks
|
||||
|
@ -297,6 +329,25 @@ def view_response_bytes(line):
|
|||
else:
|
||||
print "Request %s does not have a response" % req.reqid
|
||||
|
||||
@crochet.wait_for(timeout=None)
|
||||
@defer.inlineCallbacks
|
||||
def pretty_print_response(line):
|
||||
"""
|
||||
Print the body of the request pretty printed.
|
||||
Usage: pretty_print_request <format> <reqid(s)>
|
||||
"""
|
||||
args = shlex.split(line)
|
||||
if len(args) < 2:
|
||||
raise PappyException("Usage: pretty_print_request <format> <reqid(s)>")
|
||||
reqids = args[1]
|
||||
|
||||
reqs = yield load_reqlist(reqids)
|
||||
for req in reqs:
|
||||
if req.response:
|
||||
pretty_print_body(args[0], req.response.body)
|
||||
else:
|
||||
print 'No response associated with request %s' % req.reqid
|
||||
|
||||
@crochet.wait_for(timeout=None)
|
||||
@defer.inlineCallbacks
|
||||
def dump_response(line):
|
||||
|
@ -345,9 +396,11 @@ def load_cmds(cmd):
|
|||
'view_request_headers': (view_request_headers, None),
|
||||
'view_full_request': (view_full_request, None),
|
||||
'view_request_bytes': (view_request_bytes, None),
|
||||
'pretty_print_request': (pretty_print_request, None),
|
||||
'view_response_headers': (view_response_headers, None),
|
||||
'view_full_response': (view_full_response, None),
|
||||
'view_response_bytes': (view_response_bytes, None),
|
||||
'pretty_print_response': (pretty_print_response, None),
|
||||
'site_map': (site_map, None),
|
||||
'dump_response': (dump_response, None),
|
||||
})
|
||||
|
@ -357,9 +410,11 @@ def load_cmds(cmd):
|
|||
('view_request_headers', 'vhq'),
|
||||
('view_full_request', 'vfq'),
|
||||
('view_request_bytes', 'vbq'),
|
||||
('pretty_print_request', 'ppq'),
|
||||
('view_response_headers', 'vhs'),
|
||||
('view_full_response', 'vfs'),
|
||||
('view_response_bytes', 'vbs'),
|
||||
('pretty_print_response', 'pps'),
|
||||
('site_map', 'sm'),
|
||||
#('dump_response', 'dr'),
|
||||
])
|
||||
|
|
|
@ -119,6 +119,7 @@ def submit_current_buffer():
|
|||
full_request = '\n'.join(curbuf)
|
||||
commdata = {'action': 'submit',
|
||||
'full_message': base64.b64encode(full_request),
|
||||
'tags': ['repeater'],
|
||||
'port': int(vim.eval("s:repport")),
|
||||
'host': vim.eval("s:rephost")}
|
||||
if vim.eval("s:repisssl") == '1':
|
||||
|
|
|
@ -5,6 +5,7 @@ SHORT_NAME = '{{short_name}}'
|
|||
runargs = []
|
||||
|
||||
def init(args):
|
||||
global runargs
|
||||
runargs = args
|
||||
|
||||
def mangle_request(request):
|
||||
|
|
|
@ -846,6 +846,24 @@ def test_request_url_blankpath():
|
|||
assert r.full_path == '/?foo=bar'
|
||||
assert r.url == 'https://www.google.com?foo=bar'
|
||||
|
||||
def test_request_modify_header2():
|
||||
r = http.Request(('POST /some/path HTTP/1.1\r\n'
|
||||
'Host: test.host.thing\r\n'
|
||||
'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.10; rv:43.0) Gecko/20100101 Firefox/43.0\r\n'
|
||||
'Content-Length: 282\r\n'
|
||||
'Connection: keep-alive\r\n'
|
||||
'\r\n'
|
||||
'a|b|c|d'))
|
||||
r2 = r.copy()
|
||||
r2.headers['User-Agent'] = 'Moziller/6.9'
|
||||
assert r2.full_message == ('POST /some/path HTTP/1.1\r\n'
|
||||
'Host: test.host.thing\r\n'
|
||||
'User-Agent: Moziller/6.9\r\n'
|
||||
'Content-Length: 7\r\n'
|
||||
'Connection: keep-alive\r\n'
|
||||
'\r\n'
|
||||
'a|b|c|d')
|
||||
|
||||
|
||||
####################
|
||||
## Response tests
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue