Skip to content

Commit

Permalink
make --headers output of fetch command resemble curl format, and also…
Browse files Browse the repository at this point in the history
… show request headers
pablohoffman committed Jun 6, 2011
1 parent 0375174 commit f793515
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions scrapy/commands/fetch.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import pprint

from w3lib.url import is_url

from scrapy import log
@@ -29,9 +27,16 @@ def add_options(self, parser):
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 @@ def run(self, args, opts):
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:

0 comments on commit f793515

Please sign in to comment.