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: 2 additions & 0 deletions httpie/output/formatters/json.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ def format_body(self, body: str, mime: str) -> str:
'javascript',
'text',
]
# Media type names are case insensitive, so APPLICATION/JSON is JSON too.
mime = mime.lower()
if (self.kwargs['explicit_json']
or any(token in mime for token in maybe_json)):
from ..utils import load_prefixed_json
Expand Down
21 changes: 21 additions & 0 deletions tests/test_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,27 @@ def test_json_formatter_with_body_preceded_by_non_json_data(
assert expected_body in r


@pytest.mark.parametrize(
'content_type',
[
'application/json',
'APPLICATION/JSON',
'Application/Problem+JSON; charset=utf-8',
],
)
@responses.activate
def test_json_formatter_ignores_content_type_case(content_type):
"""Media type names are case insensitive."""
responses.add(
responses.GET,
DUMMY_URL,
body='{"message":"ok"}',
content_type=content_type,
)
r = http('--pretty=format', '--body', DUMMY_URL)
assert '{\n "message": "ok"\n}' in r


@responses.activate
def test_duplicate_keys_support_from_response():
"""JSON with duplicate keys should be handled correctly."""
Expand Down
Loading