Skip to content
Myr

Fix automatic .read() when Response instances are created with content=<str> (#1324)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Tom Christie · committed by GitHub · parent 320bfe1 · Browse files · 2 files+14 added−1 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+14 added−1 removed

  • tests:+13 added−0 removed
  • other:+1 added−1 removed

2 files+14 added−1 removed

modified:httpx/_models.py+1 added-1 removed
898 unmodified lines
899 else:900 headers, stream = encode_response(content, text, html, json)901 self._prepare(headers)902 self.stream = stream903 if content is None or isinstance(content, bytes):903 if content is None or isinstance(content, (bytes, str)):904 # Load the response body, except for streaming content.905 self.read()906907 self._num_bytes_downloaded = 0
559 unmodified lines
modified:tests/models/test_responses.py+13 added
36 unmodified lines
37 assert response.request.url == "https://example.org"38 assert not response.is_error394041def test_response_content():42 response = httpx.Response(200, content="Hello, world!")4344 assert response.status_code == 20045 assert response.reason_phrase == "OK"46 assert response.text == "Hello, world!"47 assert response.headers == httpx.Headers(48 {49 "Content-Length": "13",50 }51 )525354def test_response_text():55 response = httpx.Response(200, text="Hello, world!")5657 assert response.status_code == 200
697 unmodified lines