diff --git a/httpcore/_api.py b/httpcore/_api.py index 38b961d1..b76683cc 100644 --- a/httpcore/_api.py +++ b/httpcore/_api.py @@ -66,7 +66,7 @@ def stream( When using the `stream()` function, the body of the response will not be automatically read. If you want to access the response body you should - either use `content = response.read()`, or `for chunk in response.iter_content()`. + either use `content = response.read()`, or `for chunk in response.iter_stream()`. Arguments: method: The HTTP method for the request. Typically one of `"GET"`, diff --git a/tests/test_models.py b/tests/test_models.py index 7dd6e419..c11149e1 100644 --- a/tests/test_models.py +++ b/tests/test_models.py @@ -117,6 +117,19 @@ def test_response(): assert repr(response.stream) == "" +def test_response_streaming_api_names(): + # The public docstrings (e.g. `httpcore.stream()`) tell users to read a + # streamed body with `response.read()` or `for chunk in response.iter_stream()`. + # Pin those method names so the documented API cannot silently drift to a + # name that does not exist (doctests are not run in CI). + response = httpcore.Response(200) + assert hasattr(response, "read") + assert hasattr(response, "iter_stream") + assert hasattr(response, "aread") + assert hasattr(response, "aiter_stream") + assert not hasattr(response, "iter_content") + + # Tests for reading and streaming sync byte streams...