forked from extern/httpie-cli
a3a08a9a22
* Use relative imports in test * Use relative imports * Add myself to contributors :)
19 lines
552 B
Python
19 lines
552 B
Python
from ...plugins import FormatterPlugin
|
|
|
|
|
|
class HeadersFormatter(FormatterPlugin):
|
|
|
|
def __init__(self, **kwargs):
|
|
super().__init__(**kwargs)
|
|
self.enabled = self.format_options['headers']['sort']
|
|
|
|
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)
|