Checking headers to determine auto-streaming (#1383)

This commit is contained in:
Brian Egleston 2022-05-06 00:59:22 -06:00 committed by GitHub
parent 5e76ebc5e1
commit 9f7612cdeb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 1 deletions

View File

@ -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

View File

@ -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