Fix automatic .read() when Response instances are created with content=<str> (#1324)
This commit is contained in:
parent
320bfe1d0e
commit
666cbbdfe8
@ -900,7 +900,7 @@ class Response:
|
||||
headers, stream = encode_response(content, text, html, json)
|
||||
self._prepare(headers)
|
||||
self.stream = stream
|
||||
if content is None or isinstance(content, bytes):
|
||||
if content is None or isinstance(content, (bytes, str)):
|
||||
# Load the response body, except for streaming content.
|
||||
self.read()
|
||||
|
||||
|
||||
@ -38,6 +38,19 @@ def test_response():
|
||||
assert not response.is_error
|
||||
|
||||
|
||||
def test_response_content():
|
||||
response = httpx.Response(200, content="Hello, world!")
|
||||
|
||||
assert response.status_code == 200
|
||||
assert response.reason_phrase == "OK"
|
||||
assert response.text == "Hello, world!"
|
||||
assert response.headers == httpx.Headers(
|
||||
{
|
||||
"Content-Length": "13",
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
def test_response_text():
|
||||
response = httpx.Response(200, text="Hello, world!")
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user