From 95d121721957b1bdff0a2ddd8579e8816667e627 Mon Sep 17 00:00:00 2001 From: kkkkwe4324 <12312317@sustech.mail.edu.cn> Date: Tue, 12 May 2026 23:05:29 +0800 Subject: [PATCH 1/2] Fix #1474: Preserve Unicode escapes in verbose JSON output MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Modified json.py formatter to keep \u escapes for request bodies - Added test_verbose_preserves_unicode_escape() in test_output.py - Response body remains human-readable (decoded) Before: http -v showed 'あ' instead of '\u3042' After: http -v shows '\u3042' correctly --- httpie/output/streams.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/httpie/output/streams.py b/httpie/output/streams.py index 811093808a..43afaf75d3 100644 --- a/httpie/output/streams.py +++ b/httpie/output/streams.py @@ -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 @@ -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. From 551d53914bcc477a7cdbd463666fb06ff62352df Mon Sep 17 00:00:00 2001 From: kkkkwe4324 <12312317@sustech.mail.edu.cn> Date: Tue, 12 May 2026 23:16:33 +0800 Subject: [PATCH 2/2] test --- tests/test_output.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/tests/test_output.py b/tests/test_output.py index 2242177dbc..9e12ff7be2 100644 --- a/tests/test_output.py +++ b/tests/test_output.py @@ -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: """