@@ -41,6 +41,10 @@ def serialize(self, headers: Dict[str, Union[str, List[str]]], cookies: List[Coo
4141 # Duplicate headers are combined with commas and included in the headers field.
4242 combined_headers : Dict [str , str ] = {}
4343 for key , values in headers .items ():
44+ # omit headers with explicit null values
45+ if values is None :
46+ continue
47+
4448 if isinstance (values , str ):
4549 combined_headers [key ] = values
4650 else :
@@ -60,13 +64,15 @@ def serialize(self, headers: Dict[str, Union[str, List[str]]], cookies: List[Coo
6064 https://docs.aws.amazon.com/elasticloadbalancing/latest/application/lambda-functions.html#multi-value-headers-response
6165 """
6266 payload : Dict [str , List [str ]] = defaultdict (list )
63-
6467 for key , values in headers .items ():
68+ # omit headers with explicit null values
69+ if values is None :
70+ continue
71+
6572 if isinstance (values , str ):
6673 payload [key ].append (values )
6774 else :
68- for value in values :
69- payload [key ].append (value )
75+ payload [key ].extend (values )
7076
7177 if cookies :
7278 payload .setdefault ("Set-Cookie" , [])
@@ -98,6 +104,10 @@ def serialize(self, headers: Dict[str, Union[str, List[str]]], cookies: List[Coo
98104 payload ["headers" ]["Set-Cookie" ] = str (cookies [- 1 ])
99105
100106 for key , values in headers .items ():
107+ # omit headers with explicit null values
108+ if values is None :
109+ continue
110+
101111 if isinstance (values , str ):
102112 payload ["headers" ][key ] = values
103113 else :
0 commit comments