1
0
mirror of https://github.com/httpie/cli.git synced 2024-11-24 08:22:22 +02:00

Sort headers by name when prettifying.

This commit is contained in:
Jakub Roztocil 2012-08-03 00:58:01 +02:00
parent 4b1a04e5ed
commit 4615011f2e

View File

@ -224,10 +224,23 @@ class PygmentsProcessor(BaseProcessor):
return content
class HeadersProcessor(BaseProcessor):
"""
Sorts headers by name retaining relative order of multiple headers
with the same name.
"""
def process_headers(self, headers):
lines = headers.splitlines()
headers = sorted(lines[1:], key=lambda h: h.split(':')[0])
return '\n'.join(lines[:1] + headers)
class OutputProcessor(object):
installed_processors = [
JSONProcessor,
HeadersProcessor,
PygmentsProcessor
]