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
6 changes: 5 additions & 1 deletion httpie/output/streams.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from .processing import Conversion, Formatting
from ..context import Environment
from ..encoding import smart_decode, smart_encode, UTF8
from ..models import HTTPMessage, OutputOptions
from ..models import HTTPMessage, HTTPRequest, OutputOptions
from ..utils import parse_content_type_header


Expand Down Expand Up @@ -217,6 +217,10 @@ def iter_body(self) -> Iterable[bytes]:
first_chunk = False

def process_body(self, chunk: Union[str, bytes]) -> bytes:
if isinstance(self.msg, HTTPRequest) and self.mime == 'application/json':
if isinstance(chunk, (bytes, bytearray)):
return bytes(chunk)
return smart_encode(chunk, self.output_encoding)
if not isinstance(chunk, str):
# Text when a converter has been used,
# otherwise it will always be bytes.
Expand Down
9 changes: 9 additions & 0 deletions tests/test_output.py
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,15 @@ def test_format_option(self, httpbin):
assert r.strip().count('\n') == 2
assert COLOR not in r

def test_verbose_json_request_body_preserves_unicode_escapes(self):
r = http(
'--verbose', '--offline', '--pretty=format',
'example.org',
f'a:={json.dumps(chr(0x3042))}',
)
assert '{"a": "\\u3042"}' in r
assert chr(0x3042) not in r


class TestLineEndings:
"""
Expand Down
Loading