From f79351556577536f9d09910481919ca5a11d99e4 Mon Sep 17 00:00:00 2001 From: Pablo Hoffman Date: Mon, 6 Jun 2011 15:21:50 -0300 Subject: [PATCH] make --headers output of fetch command resemble curl format, and also show request headers --- scrapy/commands/fetch.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/scrapy/commands/fetch.py b/scrapy/commands/fetch.py index 444de6e41..d26d3bfd4 100644 --- a/scrapy/commands/fetch.py +++ b/scrapy/commands/fetch.py @@ -1,5 +1,3 @@ -import pprint - from w3lib.url import is_url from scrapy import log @@ -29,9 +27,16 @@ class Command(ScrapyCommand): parser.add_option("--headers", dest="headers", action="store_true", \ help="print response HTTP headers instead of body") + def _print_headers(self, headers, prefix): + for key, values in headers.items(): + for value in values: + print '%s %s: %s' % (prefix, key, value) + def _print_response(self, response, opts): if opts.headers: - pprint.pprint(response.headers) + self._print_headers(response.request.headers, '>') + print '>' + self._print_headers(response.headers, '<') else: print response.body @@ -40,6 +45,7 @@ class Command(ScrapyCommand): raise UsageError() cb = lambda x: self._print_response(x, opts) request = Request(args[0], callback=cb, dont_filter=True) + request.meta['handle_httpstatus_all'] = True spider = None if opts.spider: