mirror of
https://github.com/Grasscutters/mitmproxy.git
synced 2024-11-30 03:14:22 +00:00
Rationalize pathoc arguments, add -r flag to randomly select a request from the provided specs
This commit is contained in:
parent
384abbfdd5
commit
ac4e9f8cb5
@ -36,7 +36,14 @@ def go_pathoc():
|
|||||||
)
|
)
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
"-n", dest='repeat', default=1, type=int, metavar="N",
|
"-n", dest='repeat', default=1, type=int, metavar="N",
|
||||||
help='Repeat requests N times'
|
help='Repeat N times'
|
||||||
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
"-r", dest="random", action="store_true", default=False,
|
||||||
|
help="""
|
||||||
|
Select a random request from those specified. If this is not specified,
|
||||||
|
requests are all played in sequence.
|
||||||
|
"""
|
||||||
)
|
)
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
"-t", dest="timeout", type=int, default=None,
|
"-t", dest="timeout", type=int, default=None,
|
||||||
@ -48,7 +55,7 @@ def go_pathoc():
|
|||||||
help='Host and port to connect to'
|
help='Host and port to connect to'
|
||||||
)
|
)
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
'request', type=str, nargs="+",
|
'requests', type=str, nargs="+",
|
||||||
help="""
|
help="""
|
||||||
Request specification, or path to a file containing request
|
Request specification, or path to a file containing request
|
||||||
specifcations
|
specifcations
|
||||||
@ -110,7 +117,7 @@ def go_pathoc():
|
|||||||
help="Print full request"
|
help="Print full request"
|
||||||
)
|
)
|
||||||
group.add_argument(
|
group.add_argument(
|
||||||
"-r", dest="showresp", action="store_true", default=False,
|
"-p", dest="showresp", action="store_true", default=False,
|
||||||
help="Print full response"
|
help="Print full response"
|
||||||
)
|
)
|
||||||
group.add_argument(
|
group.add_argument(
|
||||||
@ -155,7 +162,7 @@ def go_pathoc():
|
|||||||
args.connect_to = None
|
args.connect_to = None
|
||||||
|
|
||||||
reqs = []
|
reqs = []
|
||||||
for r in args.request:
|
for r in args.requests:
|
||||||
if os.path.exists(r):
|
if os.path.exists(r):
|
||||||
data = open(r).read()
|
data = open(r).read()
|
||||||
r = data
|
r = data
|
||||||
@ -165,7 +172,7 @@ def go_pathoc():
|
|||||||
print >> sys.stderr, "Error parsing request spec: %s"%v.msg
|
print >> sys.stderr, "Error parsing request spec: %s"%v.msg
|
||||||
print >> sys.stderr, v.marked()
|
print >> sys.stderr, v.marked()
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
args.request = reqs
|
args.requests = reqs
|
||||||
pathoc.main(args)
|
pathoc.main(args)
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
import sys
|
import sys
|
||||||
import os
|
import os
|
||||||
|
import random
|
||||||
from netlib import tcp, http, certutils
|
from netlib import tcp, http, certutils
|
||||||
import netlib.utils
|
import netlib.utils
|
||||||
|
|
||||||
@ -189,7 +190,7 @@ class Pathoc(tcp.TCPClient):
|
|||||||
if resp:
|
if resp:
|
||||||
self._show_summary(fp, *resp)
|
self._show_summary(fp, *resp)
|
||||||
|
|
||||||
if self.sslinfo:
|
if showssl and self.sslinfo:
|
||||||
print >> fp, "Cipher: %s, %s bit, %s"%self.sslinfo.cipher
|
print >> fp, "Cipher: %s, %s bit, %s"%self.sslinfo.cipher
|
||||||
print >> fp, "SSL certificate chain:\n"
|
print >> fp, "SSL certificate chain:\n"
|
||||||
for i in self.sslinfo.certchain:
|
for i in self.sslinfo.certchain:
|
||||||
@ -239,7 +240,11 @@ def main(args):
|
|||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
if args.timeout:
|
if args.timeout:
|
||||||
p.settimeout(args.timeout)
|
p.settimeout(args.timeout)
|
||||||
for spec in args.request:
|
if args.random:
|
||||||
|
playlist = [random.choice(args.requests)]
|
||||||
|
else:
|
||||||
|
playlist = args.requests
|
||||||
|
for spec in playlist:
|
||||||
ret = p.print_request(
|
ret = p.print_request(
|
||||||
spec,
|
spec,
|
||||||
showreq=args.showreq,
|
showreq=args.showreq,
|
||||||
|
Loading…
Reference in New Issue
Block a user