import httpcore
+def test_request_repr():
+ request = httpcore.Request("GET", "http://example.org")
+ assert repr(request) == "<Request('GET', 'http://example.org')>"
+
+
def test_host_header():
request = httpcore.Request("GET", "http://example.org")
request.prepare()
assert response.text == "Hello, world!"
+def test_response_repr():
+ response = httpcore.Response(200, content=b"Hello, world!")
+ assert repr(response) == "<Response(200, 'OK')>"
+
+
def test_response_content_type_encoding():
"""
Use the charset encoding in the Content-Type header if possible.
assert response.encoding == "EUC-JP"
-def test_response():
+def test_response_default_text_encoding():
"""
A media type of 'text/*' with no charset should default to ISO-8859-1.
See: https://www.w3.org/Protocols/rfc2616/rfc2616-sec3.html#sec3.7.1
assert response.encoding == "utf-8"
+def test_response_non_text_encoding():
+ """
+ Default to apparent encoding for non-text content-type headers.
+ """
+ headers = {"Content-Type": "image/png"}
+ response = httpcore.Response(200, content=b"xyz", headers=headers)
+ assert response.text == "xyz"
+ assert response.encoding == "ascii"
+
+
def test_response_set_explicit_encoding():
headers = {
"Content-Type": "text-plain; charset=utf-8"