File tree Expand file tree Collapse file tree 1 file changed +34
-0
lines changed
tests/functional/event_handler/required_dependencies Expand file tree Collapse file tree 1 file changed +34
-0
lines changed Original file line number Diff line number Diff line change @@ -881,3 +881,37 @@ async def send(message: dict[str, Any]) -> None:
881881
882882 # THEN nothing is sent (early return)
883883 assert send_called is False
884+
885+
886+ @pytest .mark .asyncio
887+ async def test_asgi_binary_response ():
888+ # GIVEN an app that returns binary data (bytes body is auto base64 encoded)
889+ app = HttpResolverAlpha ()
890+ binary_data = b"\x89 PNG\r \n \x1a \n \x00 \x00 \x00 " # PNG header bytes
891+
892+ @app .get ("/image" )
893+ def get_image ():
894+ # When body is bytes, Response auto base64 encodes it
895+ return Response (
896+ status_code = 200 ,
897+ content_type = "image/png" ,
898+ body = binary_data ,
899+ )
900+
901+ scope = {
902+ "type" : "http" ,
903+ "method" : "GET" ,
904+ "path" : "/image" ,
905+ "query_string" : b"" ,
906+ "headers" : [],
907+ }
908+
909+ receive = make_asgi_receive ()
910+ send , captured = make_asgi_send ()
911+
912+ # WHEN called via ASGI interface
913+ await app (scope , receive , send )
914+
915+ # THEN it decodes base64 and returns binary data
916+ assert captured ["status_code" ] == 200
917+ assert captured ["body" ] == binary_data
You can’t perform that action at this time.
0 commit comments