@@ -682,3 +682,57 @@ async def app(scope, receive, send):
682682 "headers" : {"content-type" : "text/plain; charset=utf-8" },
683683 "body" : "Hello, world!" ,
684684 }
685+
686+
687+ @pytest .mark .parametrize (
688+ "mock_http_event,response_headers,expected_headers,expected_multi_value_headers" ,
689+ [
690+ [
691+ ["GET" , None , None ],
692+ [[b"key1" , b"value1" ], [b"key2" , b"value2" ]],
693+ {"key1" : "value1" , "key2" : "value2" },
694+ {},
695+ ],
696+ [
697+ ["GET" , None , None ],
698+ [[b"key1" , b"value1" ], [b"key1" , b"value2" ]],
699+ {},
700+ {"key1" : ["value1" , "value2" ]},
701+ ],
702+ [
703+ ["GET" , None , None ],
704+ [[b"key1" , b"value1" ], [b"key1" , b"value2" ], [b"key1" , b"value3" ]],
705+ {},
706+ {"key1" : ["value1" , "value2" , "value3" ]},
707+ ],
708+ [["GET" , None , None ], [], {}, {}],
709+ ],
710+ indirect = ["mock_http_event" ],
711+ )
712+ def test_http_response_headers (
713+ mock_http_event , response_headers , expected_headers , expected_multi_value_headers
714+ ) -> None :
715+ async def app (scope , receive , send ):
716+ await send (
717+ {
718+ "type" : "http.response.start" ,
719+ "status" : 200 ,
720+ "headers" : [[b"content-type" , b"text/plain; charset=utf-8" ]]
721+ + response_headers ,
722+ }
723+ )
724+ await send ({"type" : "http.response.body" , "body" : b"Hello, world!" })
725+
726+ handler = Mangum (app , lifespan = "off" )
727+ response = handler (mock_http_event , {})
728+ expected = {
729+ "statusCode" : 200 ,
730+ "isBase64Encoded" : False ,
731+ "headers" : {"content-type" : "text/plain; charset=utf-8" },
732+ "body" : "Hello, world!" ,
733+ }
734+ if expected_headers :
735+ expected ["headers" ].update (expected_headers )
736+ if expected_multi_value_headers :
737+ expected ["multiValueHeaders" ] = expected_multi_value_headers
738+ assert response == expected
0 commit comments