From 059a2329035b916c8762b58a385556266abb4629 Mon Sep 17 00:00:00 2001 From: Aldo Cortesi Date: Sat, 21 Jul 2012 16:19:44 +1200 Subject: [PATCH] Add support for client timeout to pathoc. --- libpathod/pathoc.py | 9 ++++++--- pathoc | 10 ++++++++-- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/libpathod/pathoc.py b/libpathod/pathoc.py index 3791c1168..f79ed3afc 100644 --- a/libpathod/pathoc.py +++ b/libpathod/pathoc.py @@ -45,7 +45,10 @@ class Pathoc(tcp.TCPClient): except http.HttpError, v: print >> fp, v.msg return - if verbose: - print_full(fp, *ret) + except tcp.NetLibTimeout: + print >> fp, "Timeout" else: - print_short(fp, *ret) + if verbose: + print_full(fp, *ret) + else: + print_short(fp, *ret) diff --git a/pathoc b/pathoc index 7f5555668..93da37982 100755 --- a/pathoc +++ b/pathoc @@ -5,6 +5,10 @@ from netlib import tcp if __name__ == "__main__": parser = argparse.ArgumentParser(description='A perverse HTTP client.') + parser.add_argument( + "-i", dest="sni", type=str, default=False, + help="SSL Server Name Indication." + ) parser.add_argument( "-n", dest='repeat', default=1, type=int, metavar="N", help='Repeat requests N times.' @@ -18,8 +22,8 @@ if __name__ == "__main__": help="Connect with SSL." ) parser.add_argument( - "-i", dest="sni", type=str, default=False, - help="SSL Server Name Indication." + "-t", dest="timeout", type=int, default=None, + help="Connection timeout." ) parser.add_argument( "-v", dest="verbose", action='count', @@ -50,4 +54,6 @@ if __name__ == "__main__": sys.exit(1) if args.ssl: p.convert_to_ssl(sni=args.sni) + if args.timeout: + p.settimeout(args.timeout) p.print_requests(args.request, args.verbose)