@@ -41,6 +41,10 @@ def serialize(self, headers: Dict[str, Union[str, List[str]]], cookies: List[Coo
41
41
# Duplicate headers are combined with commas and included in the headers field.
42
42
combined_headers : Dict [str , str ] = {}
43
43
for key , values in headers .items ():
44
+ # omit headers with explicit null values
45
+ if values is None :
46
+ continue
47
+
44
48
if isinstance (values , str ):
45
49
combined_headers [key ] = values
46
50
else :
@@ -60,13 +64,15 @@ def serialize(self, headers: Dict[str, Union[str, List[str]]], cookies: List[Coo
60
64
https://docs.aws.amazon.com/elasticloadbalancing/latest/application/lambda-functions.html#multi-value-headers-response
61
65
"""
62
66
payload : Dict [str , List [str ]] = defaultdict (list )
63
-
64
67
for key , values in headers .items ():
68
+ # omit headers with explicit null values
69
+ if values is None :
70
+ continue
71
+
65
72
if isinstance (values , str ):
66
73
payload [key ].append (values )
67
74
else :
68
- for value in values :
69
- payload [key ].append (value )
75
+ payload [key ].extend (values )
70
76
71
77
if cookies :
72
78
payload .setdefault ("Set-Cookie" , [])
@@ -98,6 +104,10 @@ def serialize(self, headers: Dict[str, Union[str, List[str]]], cookies: List[Coo
98
104
payload ["headers" ]["Set-Cookie" ] = str (cookies [- 1 ])
99
105
100
106
for key , values in headers .items ():
107
+ # omit headers with explicit null values
108
+ if values is None :
109
+ continue
110
+
101
111
if isinstance (values , str ):
102
112
payload ["headers" ][key ] = values
103
113
else :
0 commit comments