Skip to content

Commit 9f7612c

Browse files
authored
Checking headers to determine auto-streaming (#1383)
1 parent 5e76ebc commit 9f7612c

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

httpie/output/writer.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
from .streams import (
1818
BaseStream, BufferedPrettyStream, EncodedStream, PrettyStream, RawStream,
1919
)
20+
from ..utils import parse_content_type_header
2021

2122

2223
MESSAGE_SEPARATOR = '\n\n'
@@ -163,7 +164,10 @@ def get_stream_type_and_kwargs(
163164
if not is_stream and message_type is HTTPResponse:
164165
# If this is a response, then check the headers for determining
165166
# auto-streaming.
166-
is_stream = headers.get('Content-Type') == 'text/event-stream'
167+
raw_content_type_header = headers.get('Content-Type', None)
168+
if raw_content_type_header:
169+
content_type_header, _ = parse_content_type_header(raw_content_type_header)
170+
is_stream = (content_type_header == 'text/event-stream')
167171

168172
if not env.stdout_isatty and not prettify_groups:
169173
stream_class = RawStream

tests/test_stream.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,10 @@ def test_redirected_stream(httpbin):
124124
['Accept:text/event-stream'],
125125
3
126126
),
127+
(
128+
['Accept:text/event-stream; charset=utf-8'],
129+
3
130+
),
127131
(
128132
['Accept:text/plain'],
129133
1

0 commit comments

Comments
 (0)