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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
This document records all notable changes to [HTTPie](https://httpie.io).
This project adheres to [Semantic Versioning](https://semver.org/).

## Unreleased

- Format XML responses with uppercase or mixed-case media types.

## [3.2.4](https://github.com/httpie/cli/compare/3.2.3...3.2.4) (2024-11-01)

- Fix default certs loading and unpin `requests`. ([#1596](https://github.com/httpie/cli/issues/1596))
Expand Down
2 changes: 1 addition & 1 deletion docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1892,7 +1892,7 @@ Formatting has the following effects:
- HTTP headers are sorted by name.
- JSON data is indented, sorted by keys, and unicode escapes are converted
to the characters they represent.
- XML and XHTML data is indented.
- XML and XHTML data is indented. XML media types are matched case-insensitively.

Please note that sometimes there might be changes made by formatters on the actual response body (e.g.,
collapsing empty tags on XML) but the end result will always be semantically indistinguishable. Some of
Expand Down
2 changes: 1 addition & 1 deletion httpie/output/formatters/xml.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def __init__(self, **kwargs):
self.enabled = self.format_options['xml']['format']

def format_body(self, body: str, mime: str):
if 'xml' not in mime:
if 'xml' not in mime.lower():
return body

from xml.parsers.expat import ExpatError
Expand Down
17 changes: 17 additions & 0 deletions tests/test_xml.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,3 +97,20 @@ def test_invalid_xml(file):
# No formatting done, data is simply printed as-is.
r = http(DUMMY_URL)
assert xml_data in r


@pytest.mark.parametrize('content_type', [
'APPLICATION/XML',
'Application/Atom+XML; charset=utf-8',
])
@responses.activate
def test_xml_media_type_is_case_insensitive(content_type):
responses.add(
responses.GET,
DUMMY_URL,
body=XML_DATA_RAW,
content_type=content_type,
)

r = http('--pretty=format', '--body', DUMMY_URL)
assert XML_DATA_FORMATTED in r
Loading