@@ -252,6 +252,47 @@ async def test_urlencoded_list():
252252 assert async_content == b"example=a&example=1&example=true"
253253
254254
255+ @pytest .mark .anyio
256+ async def test_utf8_content ():
257+ request = httpx .Request (method , url , content = "Hello\ud83d \udca4 , world!" )
258+ assert isinstance (request .stream , typing .Iterable )
259+ assert isinstance (request .stream , typing .AsyncIterable )
260+
261+ sync_content = b"" .join (list (request .stream ))
262+ async_content = b"" .join ([part async for part in request .stream ])
263+ assert request .headers == {"Host" : "www.example.com" , "Content-Length" : "13" }
264+ assert sync_content == b"Hello, world!"
265+ assert async_content == b"Hello, world!"
266+
267+ # Support 'data' for compat with requests.
268+ with pytest .warns (DeprecationWarning ):
269+ request = httpx .Request (method , url , data = "Hello\ud83d \udca4 , world!" ) # type: ignore
270+ assert isinstance (request .stream , typing .Iterable )
271+ assert isinstance (request .stream , typing .AsyncIterable )
272+
273+ sync_content = b"" .join (list (request .stream ))
274+ async_content = b"" .join ([part async for part in request .stream ])
275+
276+ assert request .headers == {"Host" : "www.example.com" , "Content-Length" : "13" }
277+ assert sync_content == b"Hello, world!"
278+ assert async_content == b"Hello, world!"
279+
280+ request = httpx .Request (method , url , json = {"Hello\ud83d \udca4 " : "world!\ud83d \udca4 " })
281+ assert isinstance (request .stream , typing .Iterable )
282+ assert isinstance (request .stream , typing .AsyncIterable )
283+
284+ sync_content = b"" .join (list (request .stream ))
285+ async_content = b"" .join ([part async for part in request .stream ])
286+
287+ assert request .headers == {
288+ "Host" : "www.example.com" ,
289+ "Content-Length" : "18" ,
290+ "Content-Type" : "application/json" ,
291+ }
292+ assert sync_content == b'{"Hello":"world!"}'
293+ assert async_content == b'{"Hello":"world!"}'
294+
295+
255296@pytest .mark .anyio
256297async def test_multipart_files_content ():
257298 files = {"file" : io .BytesIO (b"<file content>" )}
0 commit comments