|
25 | 25 | builtin_str,
|
26 | 26 | cookielib,
|
27 | 27 | getproxies,
|
| 28 | + is_urllib3_2, |
28 | 29 | urlparse,
|
29 | 30 | )
|
30 | 31 | from requests.cookies import cookiejar_from_dict, morsel_to_cookie
|
@@ -1810,23 +1811,6 @@ def test_autoset_header_values_are_native(self, httpbin):
|
1810 | 1811 |
|
1811 | 1812 | assert p.headers["Content-Length"] == length
|
1812 | 1813 |
|
1813 |
| - def test_content_length_for_bytes_data(self, httpbin): |
1814 |
| - data = "This is a string containing multi-byte UTF-8 ☃️" |
1815 |
| - encoded_data = data.encode("utf-8") |
1816 |
| - length = str(len(encoded_data)) |
1817 |
| - req = requests.Request("POST", httpbin("post"), data=encoded_data) |
1818 |
| - p = req.prepare() |
1819 |
| - |
1820 |
| - assert p.headers["Content-Length"] == length |
1821 |
| - |
1822 |
| - def test_content_length_for_string_data_counts_bytes(self, httpbin): |
1823 |
| - data = "This is a string containing multi-byte UTF-8 ☃️" |
1824 |
| - length = str(len(data.encode("utf-8"))) |
1825 |
| - req = requests.Request("POST", httpbin("post"), data=data) |
1826 |
| - p = req.prepare() |
1827 |
| - |
1828 |
| - assert p.headers["Content-Length"] == length |
1829 |
| - |
1830 | 1814 | def test_nonhttp_schemes_dont_check_URLs(self):
|
1831 | 1815 | test_urls = (
|
1832 | 1816 | "data:image/gif;base64,R0lGODlhAQABAHAAACH5BAUAAAAALAAAAAABAAEAAAICRAEAOw==",
|
@@ -2966,6 +2950,29 @@ def response_handler(sock):
|
2966 | 2950 | assert client_cert is not None
|
2967 | 2951 |
|
2968 | 2952 |
|
| 2953 | +def test_content_length_for_bytes_data(httpbin): |
| 2954 | + data = "This is a string containing multi-byte UTF-8 ☃️" |
| 2955 | + encoded_data = data.encode("utf-8") |
| 2956 | + length = str(len(encoded_data)) |
| 2957 | + req = requests.Request("POST", httpbin("post"), data=encoded_data) |
| 2958 | + p = req.prepare() |
| 2959 | + |
| 2960 | + assert p.headers["Content-Length"] == length |
| 2961 | + |
| 2962 | + |
| 2963 | +@pytest.mark.skipif( |
| 2964 | + not is_urllib3_2, |
| 2965 | + reason="urllib3 2.x encodes all strings to utf-8, urllib3 1.x uses latin-1", |
| 2966 | +) |
| 2967 | +def test_content_length_for_string_data_counts_bytes(httpbin): |
| 2968 | + data = "This is a string containing multi-byte UTF-8 ☃️" |
| 2969 | + length = str(len(data.encode("utf-8"))) |
| 2970 | + req = requests.Request("POST", httpbin("post"), data=data) |
| 2971 | + p = req.prepare() |
| 2972 | + |
| 2973 | + assert p.headers["Content-Length"] == length |
| 2974 | + |
| 2975 | + |
2969 | 2976 | def test_json_decode_errors_are_serializable_deserializable():
|
2970 | 2977 | json_decode_error = requests.exceptions.JSONDecodeError(
|
2971 | 2978 | "Extra data",
|
|
0 commit comments