2012-06-24 09:10:10 +00:00
|
|
|
#!/usr/bin/env python
|
|
|
|
import argparse, sys
|
|
|
|
from libpathod import pathoc, version
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
parser = argparse.ArgumentParser(description='A perverse HTTP client.')
|
2012-06-24 10:59:20 +00:00
|
|
|
parser.add_argument('--port', "-p", type=int, default=None, help="Port. Defaults to 80, or 443 if SSL is active.")
|
|
|
|
parser.add_argument('--ssl', "-s", action="store_true", default=False, help="Connect with SSL.")
|
|
|
|
parser.add_argument('--verbose', '-v', action='count')
|
2012-06-24 09:10:10 +00:00
|
|
|
parser.add_argument('host', type=str, help='Host to connect to')
|
|
|
|
parser.add_argument('request', type=str, nargs="+", help='Request specification')
|
|
|
|
|
|
|
|
args = parser.parse_args()
|
2012-06-24 09:40:31 +00:00
|
|
|
|
2012-06-24 09:10:10 +00:00
|
|
|
if args.port is None:
|
|
|
|
port = 443 if args.ssl else 80
|
|
|
|
else:
|
|
|
|
port = args.port
|
|
|
|
|
2012-06-24 10:59:20 +00:00
|
|
|
|
2012-06-24 09:10:10 +00:00
|
|
|
try:
|
|
|
|
p = pathoc.Pathoc(args.ssl, args.host, port, None)
|
|
|
|
for i in args.request:
|
2012-06-24 10:59:20 +00:00
|
|
|
ret = p.request(i)
|
|
|
|
if args.verbose:
|
|
|
|
pathoc.print_full(sys.stdout, *ret)
|
|
|
|
else:
|
|
|
|
pathoc.print_short(sys.stdout, *ret)
|
|
|
|
|
2012-06-24 09:10:10 +00:00
|
|
|
except pathoc.PathocError, v:
|
2012-06-24 10:59:20 +00:00
|
|
|
print >> sys.stderr, str(v)
|
2012-06-24 09:10:10 +00:00
|
|
|
sys.exit(1)
|