From 9f7612cdeb560730651bf223ae3f2dc866c3c3f3 Mon Sep 17 00:00:00 2001 From: Brian Egleston Date: Fri, 6 May 2022 00:59:22 -0600 Subject: [PATCH] Checking headers to determine auto-streaming (#1383) --- httpie/output/writer.py | 6 +++++- tests/test_stream.py | 4 ++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/httpie/output/writer.py b/httpie/output/writer.py index c580e22c..4a2949bc 100644 --- a/httpie/output/writer.py +++ b/httpie/output/writer.py @@ -17,6 +17,7 @@ from .processing import Conversion, Formatting from .streams import ( BaseStream, BufferedPrettyStream, EncodedStream, PrettyStream, RawStream, ) +from ..utils import parse_content_type_header MESSAGE_SEPARATOR = '\n\n' @@ -163,7 +164,10 @@ def get_stream_type_and_kwargs( if not is_stream and message_type is HTTPResponse: # If this is a response, then check the headers for determining # auto-streaming. - is_stream = headers.get('Content-Type') == 'text/event-stream' + raw_content_type_header = headers.get('Content-Type', None) + if raw_content_type_header: + content_type_header, _ = parse_content_type_header(raw_content_type_header) + is_stream = (content_type_header == 'text/event-stream') if not env.stdout_isatty and not prettify_groups: stream_class = RawStream diff --git a/tests/test_stream.py b/tests/test_stream.py index a8950d29..45b8e4dd 100644 --- a/tests/test_stream.py +++ b/tests/test_stream.py @@ -124,6 +124,10 @@ def test_redirected_stream(httpbin): ['Accept:text/event-stream'], 3 ), + ( + ['Accept:text/event-stream; charset=utf-8'], + 3 + ), ( ['Accept:text/plain'], 1