From: Ben Darnell Date: Mon, 9 Aug 2010 21:12:33 +0000 (-0700) Subject: Add a simple main function to httpclient.py for manual testing X-Git-Tag: v1.1.0~43 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=00ce7d4d996ff4c5e19748a5582142fa53de33cd;p=thirdparty%2Ftornado.git Add a simple main function to httpclient.py for manual testing --- diff --git a/tornado/httpclient.py b/tornado/httpclient.py index 1e8bd976a..8894a64a5 100644 --- a/tornado/httpclient.py +++ b/tornado/httpclient.py @@ -604,3 +604,28 @@ def _utf8(value): return value.encode("utf-8") assert isinstance(value, str) return value + +def main(): + from tornado.options import define, options, parse_command_line + define("print_headers", type=bool, default=False) + define("print_body", type=bool, default=True) + define("follow_redirects", type=bool, default=True) + args = parse_command_line() + client = HTTPClient() + for arg in args: + try: + response = client.fetch(arg, + follow_redirects=options.follow_redirects) + except HTTPError, e: + if e.response is not None: + response = e.response + else: + raise + if options.print_headers: + print response.headers + if options.print_body: + print response.body + +if __name__ == "__main__": + main() +