httpie-cli/httpie/output/processors/headers.py
Jakub Roztocil 05db75bdb1 Modularized output, refactoring
Making it ready for output formatting plugin API.
2014-04-27 21:58:00 +02:00

15 lines
400 B
Python

from .base import BaseProcessor
class HeadersProcessor(BaseProcessor):
def process_headers(self, headers):
"""
Sorts headers by name while retaining relative
order of multiple headers with the same name.
"""
lines = headers.splitlines()
headers = sorted(lines[1:], key=lambda h: h.split(':')[0])
return '\r\n'.join(lines[:1] + headers)