From 00ce7d4d996ff4c5e19748a5582142fa53de33cd Mon Sep 17 00:00:00 2001 From: Ben Darnell Date: Mon, 9 Aug 2010 14:12:33 -0700 Subject: [PATCH] Add a simple main function to httpclient.py for manual testing --- tornado/httpclient.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) 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() + -- 2.47.3