mirror of
https://github.com/Grasscutters/mitmproxy.git
synced 2024-11-23 08:11:00 +00:00
Use http.read_response to read server response.
Also add a few different output formats, and a verbosity flag.
This commit is contained in:
parent
ddda57179a
commit
a747043cc8
@ -4,6 +4,16 @@ import rparse
|
|||||||
class PathocError(Exception): pass
|
class PathocError(Exception): pass
|
||||||
|
|
||||||
|
|
||||||
|
def print_short(fp, httpversion, code, msg, headers, 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, headers
|
||||||
|
print >> fp, content
|
||||||
|
|
||||||
|
|
||||||
class Pathoc(tcp.TCPClient):
|
class Pathoc(tcp.TCPClient):
|
||||||
def __init__(self, ssl, host, port, clientcert):
|
def __init__(self, ssl, host, port, clientcert):
|
||||||
try:
|
try:
|
||||||
@ -15,7 +25,5 @@ class Pathoc(tcp.TCPClient):
|
|||||||
r = rparse.parse_request({}, spec)
|
r = rparse.parse_request({}, spec)
|
||||||
r.serve(self.wfile)
|
r.serve(self.wfile)
|
||||||
self.wfile.flush()
|
self.wfile.flush()
|
||||||
|
return http.read_response(self.rfile, r.method, None)
|
||||||
line = self.rfile.readline()
|
|
||||||
print line
|
|
||||||
|
|
||||||
|
13
pathoc
13
pathoc
@ -4,8 +4,9 @@ from libpathod import pathoc, version
|
|||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
parser = argparse.ArgumentParser(description='A perverse HTTP client.')
|
parser = argparse.ArgumentParser(description='A perverse HTTP client.')
|
||||||
parser.add_argument('--port', type=int, default=None, help="Port. Defaults to 80, or 443 if SSL is active.")
|
parser.add_argument('--port', "-p", type=int, default=None, help="Port. Defaults to 80, or 443 if SSL is active.")
|
||||||
parser.add_argument('--ssl', action="store_true", default=False, help="Connect with SSL.")
|
parser.add_argument('--ssl', "-s", action="store_true", default=False, help="Connect with SSL.")
|
||||||
|
parser.add_argument('--verbose', '-v', action='count')
|
||||||
parser.add_argument('host', type=str, help='Host to connect to')
|
parser.add_argument('host', type=str, help='Host to connect to')
|
||||||
parser.add_argument('request', type=str, nargs="+", help='Request specification')
|
parser.add_argument('request', type=str, nargs="+", help='Request specification')
|
||||||
|
|
||||||
@ -16,10 +17,16 @@ if __name__ == "__main__":
|
|||||||
else:
|
else:
|
||||||
port = args.port
|
port = args.port
|
||||||
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
p = pathoc.Pathoc(args.ssl, args.host, port, None)
|
p = pathoc.Pathoc(args.ssl, args.host, port, None)
|
||||||
for i in args.request:
|
for i in args.request:
|
||||||
p.request(i)
|
ret = p.request(i)
|
||||||
|
if args.verbose:
|
||||||
|
pathoc.print_full(sys.stdout, *ret)
|
||||||
|
else:
|
||||||
|
pathoc.print_short(sys.stdout, *ret)
|
||||||
|
|
||||||
except pathoc.PathocError, v:
|
except pathoc.PathocError, v:
|
||||||
print >> sys.stderr, str(v)
|
print >> sys.stderr, str(v)
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
Loading…
Reference in New Issue
Block a user