Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion httpie/output/formatters/headers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
18 changes: 18 additions & 0 deletions tests/test_output.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
from httpie.cli.definition import parser
from httpie.encoding import UTF8
from httpie.output.formatters.colors import get_lexer, PIE_STYLE_NAMES, BUNDLED_STYLES
from httpie.output.formatters.headers import HeadersFormatter
from httpie.status import ExitStatus
from .fixtures import XML_DATA_RAW, XML_DATA_FORMATTED
from .utils import COLOR, CRLF, HTTP_OK, MockEnvironment, http, DUMMY_URL, strip_colors
Expand Down Expand Up @@ -378,6 +379,23 @@ def test_CRLF_formatted_request(self, httpbin):


class TestFormatOptions:
def test_header_sort_retains_order_for_mixed_case_repeated_fields(self):
formatter = HeadersFormatter(format_options=PARSED_DEFAULT_FORMAT_OPTIONS)
headers = CRLF.join([
'HTTP/1.1 200 OK',
'set-cookie: first=1',
'X-Z: last',
'Set-Cookie: second=2',
'accept: text/plain',
])
assert formatter.format_headers(headers) == CRLF.join([
'HTTP/1.1 200 OK',
'accept: text/plain',
'set-cookie: first=1',
'Set-Cookie: second=2',
'X-Z: last',
])

def test_header_formatting_options(self):
def get_headers(sort):
return http(
Expand Down
Loading