From 4615011f2e930a0daea7eb49e4be43abbd46a9be Mon Sep 17 00:00:00 2001 From: Jakub Roztocil Date: Fri, 3 Aug 2012 00:58:01 +0200 Subject: [PATCH] Sort headers by name when prettifying. --- httpie/output.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/httpie/output.py b/httpie/output.py index fda8549a..8f564b13 100644 --- a/httpie/output.py +++ b/httpie/output.py @@ -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 ]