Skip to content

Fix header sorting to be case-insensitive - #1976

Open
charan-rathore wants to merge 1 commit into
httpie:masterfrom
charan-rathore:fix-headers-sort-case
Open

charan-rathore wants to merge 1 commit into
httpie:masterfrom
charan-rathore:fix-headers-sort-case

Conversation

@charan-rathore

Copy link
Copy Markdown

Fixes #1960.

HeadersFormatter.format_headers sorts header lines with the key h.split(':')[0], which compares case-sensitively. ASCII uppercase letters sort before lowercase ones, so Zebra: foo was placed before apple: foo even though alphabetical sorting should be case-insensitive for header names (which are case-insensitive per RFC 9110).

This changes the sort key to h.split(':')[0].lower(), keeping the displayed header text untouched and preserving the stable relative order of repeated header names.

Added a regression test test_header_sorting_is_case_insensitive alongside the existing format-options tests. Verified the test fails before the change and passes after; full tests/test_output.py passes (122 passed, 3 xfailed).

HeadersFormatter sorted header lines with a case-sensitive key, so
uppercase names sorted before lowercase ones instead of following
alphabetical order. Compare case-insensitively while keeping the
original text untouched.

Fixes httpie#1960.

Signed-off-by: Charan Rathore <180254320+charan-rathore@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Header formatting reorders repeated fields with mixed capitalization

1 participant