aboutsummaryrefslogtreecommitdiffstats
path: root/libpathod
diff options
context:
space:
mode:
authorAldo Cortesi <aldo@nullcube.com>2012-07-21 20:20:37 +1200
committerAldo Cortesi <aldo@nullcube.com>2012-07-21 20:20:37 +1200
commit86fe199988801232f209b7e39a2910065bf5db5f (patch)
treea4ef1fd23686b1404f8a3f3352a3b647aac52451 /libpathod
parent059a2329035b916c8762b58a385556266abb4629 (diff)
downloadmitmproxy-86fe199988801232f209b7e39a2910065bf5db5f.tar.gz
mitmproxy-86fe199988801232f209b7e39a2910065bf5db5f.tar.bz2
mitmproxy-86fe199988801232f209b7e39a2910065bf5db5f.zip
pathoc: add a flag to dump request information.
Diffstat (limited to 'libpathod')
-rw-r--r--libpathod/pathoc.py26
-rw-r--r--libpathod/rparse.py17
2 files changed, 30 insertions, 13 deletions
diff --git a/libpathod/pathoc.py b/libpathod/pathoc.py
index f79ed3af..7af5a288 100644
--- a/libpathod/pathoc.py
+++ b/libpathod/pathoc.py
@@ -6,11 +6,11 @@ class PathocError(Exception): pass
def print_short(fp, httpversion, code, msg, headers, content):
- print >> fp, "%s %s: %s bytes"%(code, msg, len(content))
+ print >> fp, "<< %s %s: %s bytes"%(code, msg, len(content))
def print_full(fp, httpversion, code, msg, headers, content):
- print >> fp, "HTTP%s/%s %s %s"%(httpversion[0], httpversion[1], code, msg)
+ print >> fp, "<< HTTP%s/%s %s %s"%(httpversion[0], httpversion[1], code, msg)
print >> fp, headers
print >> fp, content
@@ -26,18 +26,28 @@ class Pathoc(tcp.TCPClient):
May raise rparse.ParseException and netlib.http.HttpError.
"""
r = rparse.parse_request({}, spec)
- r.serve(self.wfile)
+ ret = r.serve(self.wfile)
self.wfile.flush()
return http.read_response(self.rfile, r.method, None)
- def print_requests(self, reqs, verbose, fp=sys.stdout):
+ def print_requests(self, reqs, respdump, reqdump, fp=sys.stdout):
"""
Performs a series of requests, and prints results to the specified
file pointer.
"""
for i in reqs:
try:
- ret = self.request(i)
+ r = rparse.parse_request({}, i)
+ req = r.serve(self.wfile)
+ if reqdump:
+ print >> fp, ">>", req["method"], req["path"]
+ for a in req["actions"]:
+ print >> fp, "\t",
+ for x in a:
+ print x,
+ print
+ self.wfile.flush()
+ resp = self.request(i)
except rparse.ParseException, v:
print >> fp, "Error parsing request spec: %s"%v.msg
print >> fp, v.marked()
@@ -48,7 +58,7 @@ class Pathoc(tcp.TCPClient):
except tcp.NetLibTimeout:
print >> fp, "Timeout"
else:
- if verbose:
- print_full(fp, *ret)
+ if respdump:
+ print_full(fp, *resp)
else:
- print_short(fp, *ret)
+ print_short(fp, *resp)
diff --git a/libpathod/rparse.py b/libpathod/rparse.py
index 9d0f7e79..6eb7d5a4 100644
--- a/libpathod/rparse.py
+++ b/libpathod/rparse.py
@@ -130,21 +130,28 @@ class LiteralGenerator:
def __getslice__(self, a, b):
return self.s.__getslice__(a, b)
+ def __repr__(self):
+ return '"%s"'%self.s
+
class RandomGenerator:
- def __init__(self, chars, length):
- self.chars = chars
+ def __init__(self, dtype, length):
+ self.dtype = dtype
self.length = length
def __len__(self):
return self.length
def __getitem__(self, x):
- return random.choice(self.chars)
+ return random.choice(DATATYPES[self.dtype])
def __getslice__(self, a, b):
b = min(b, self.length)
- return "".join(random.choice(self.chars) for x in range(a, b))
+ chars = DATATYPES[self.dtype]
+ return "".join(random.choice(chars) for x in range(a, b))
+
+ def __repr__(self):
+ return "%s random from %s"%(self.length, self.dtype)
class FileGenerator:
@@ -205,7 +212,7 @@ class ValueGenerate:
return self.usize * self.UNITS[self.unit]
def get_generator(self, settings):
- return RandomGenerator(DATATYPES[self.datatype], self.bytes())
+ return RandomGenerator(self.datatype, self.bytes())
@classmethod
def expr(klass):