diff --git a/httpie/output/formatters/headers.py b/httpie/output/formatters/headers.py index 2188193902..1b701bee51 100644 --- a/httpie/output/formatters/headers.py +++ b/httpie/output/formatters/headers.py @@ -14,5 +14,5 @@ def format_headers(self, headers: str) -> str: """ lines = headers.splitlines() - headers = sorted(lines[1:], key=lambda h: h.split(':')[0]) + headers = sorted(lines[1:], key=lambda h: h.split(':')[0].lower()) return '\r\n'.join(lines[:1] + headers) diff --git a/tests/test_output.py b/tests/test_output.py index 2242177dbc..2adf92812e 100644 --- a/tests/test_output.py +++ b/tests/test_output.py @@ -392,6 +392,14 @@ def get_headers(sort): assert f'XXX: foo{CRLF}ZZZ: foo' in r_sorted assert f'ZZZ: foo{CRLF}XXX: foo' in r_unsorted + def test_header_sorting_is_case_insensitive(self): + r = http( + '--offline', '--print=H', + '--format-options', 'headers.sort:true', + 'example.org', 'Zebra:foo', 'apple:foo', + ) + assert r.index('apple: foo') < r.index('Zebra: foo') + @pytest.mark.parametrize( 'options, expected_json', [