Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] multiValueHeaders not being sent back (ALB) #64

Closed
amacks opened this issue Apr 30, 2020 · 5 comments
Closed

[BUG] multiValueHeaders not being sent back (ALB) #64

amacks opened this issue Apr 30, 2020 · 5 comments
Assignees

Comments

@amacks
Copy link
Contributor

amacks commented Apr 30, 2020

It looks like ALB needs support for multiValueHeaders as part of the return JSON for things like Content-Type, headers does not seem to be properly passed through the ALB. I added a multiValueHeader element by copying and modifying headers in the to_json and inner_lambda_handler and it seems to work as expected and the ALB properly interprets. I can submit a PR, but I cannot vouch for the quality of the code, however it does seem to work

diff --git a/lambdarest/__init__.py b/lambdarest/__init__.py
index d8cd80f..8079e97 100755
--- a/lambdarest/__init__.py
+++ b/lambdarest/__init__.py
@@ -22,10 +22,11 @@ class Response(object):
     if no headers are specified, empty dict is returned
     """
 
-    def __init__(self, body=None, status_code=None, headers=None):
+    def __init__(self, body=None, status_code=None, headers=None, multiValueHeaders=None):
         self.body = body
         self.status_code = status_code
         self.headers = headers
+        self.multiValueHeaders = multiValueHeaders
         self.status_code_description = None
         self.isBase64_encoded = False
 
@@ -42,8 +43,12 @@ class Response(object):
             if do_json_dumps
             else self.body,
             "statusCode": status_code,
-            "headers": self.headers or {},
         }
+        ## handle multiValueHeaders if defined, default to headers
+        if (self.multiValueHeaders == None) :
+            response["headers"] = self.headers or {}
+        else:
+            response["multiValueHeaders"] = self.multiValueHeaders
         # if body is None, remove the key
         if response.get("body") == None:
             response.pop("body")
@@ -235,21 +240,22 @@ def create_lambda_handler(
                             raise ValueError("Response tuple has more than 3 items")
 
                         # Unpack the tuple, missing items will be defaulted
-                        body, status_code, headers = response + (None,) * (
-                            3 - response_len
+                        body, status_code, headers, multiValueHeaders = response + (None,) * (
+                            4 - response_len
                         )
 
                     elif isinstance(response, dict) and all(
-                        key in ["body", "statusCode", "headers"]
+                        key in ["body", "statusCode", "headers", "multiValueHeaders"]
                         for key in response.keys()
                     ):
                         body = response.get("body")
                         status_code = response.get("statusCode") or status_code
                         headers = response.get("headers") or headers
+                        multiValueHeaders = response.get("multiValueHeaders") or multiValueHeaders
 
                     else:  # if response is string, int, etc.
                         body = response
-                    response = Response(body, status_code, headers)
+                    response = Response(body, status_code, headers, multiValueHeaders)
                 return response.to_json(
                     encoder=json_encoder,
                     application_load_balancer=application_load_balancer,

@sloev
Copy link
Owner

sloev commented Apr 30, 2020 via email

@sloev
Copy link
Owner

sloev commented May 1, 2020

there is not enough for me here to work on, sorry.

i would like

  • a pull request with changes you want
  • a testcase or something that demonstrates new functionality

If you have time to supply any of that in a pr i will take time to verify and get it in. If not i will not have the time right now to do the journey myself, sorry :-)

@amacks
Copy link
Contributor Author

amacks commented May 6, 2020

ok, I will put together a PR in the next day or 3

@sloev
Copy link
Owner

sloev commented May 6, 2020 via email

@sloev
Copy link
Owner

sloev commented May 11, 2020

fixed in #65

@sloev sloev closed this as completed May 11, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants