1
0
mirror of https://github.com/httpie/cli.git synced 2025-01-24 03:16:43 +02:00
2019-08-31 19:13:36 +02:00

15 lines
424 B
Python

from httpie.plugins import FormatterPlugin
class HeadersFormatter(FormatterPlugin):
def format_headers(self, headers: str) -> str:
"""
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)