Skip to content

Conversation

@medinarrior
Copy link
Contributor

Issue #735

Description of changes: Adding support for multi-value query string parameters.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@sanathkr
Copy link
Contributor

@jfuss already started taking a peek at this PR. I will assign to him for review

Copy link
Contributor

@jfuss jfuss left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is looking great. A couple small comments/suggestions. Please make sure you are running integ-test and func-tests. This change will break any tests that we have which asserts the event object being passed into the function.

Add tests for multi headers and query string params:

Adjust this test to check both the query string and the multi query strings: https://github.com/awslabs/aws-sam-cli/blob/develop/tests/integration/local/start_api/test_start_api.py#L409. Adding a integ-test case for multi headers will also be beneficial.

Would you be able to adjust the APIGW events for sam local generate-event command as apart of this as well? This will keep the multi query string and headers changes together: https://github.com/awslabs/aws-sam-cli/tree/develop/samcli/commands/local/lib/generated_sample_events/events/apigateway

@jfuss jfuss self-assigned this Oct 31, 2018
@medinarrior
Copy link
Contributor Author

Still working with integ-test and func-tests.

@jfuss
Copy link
Contributor

jfuss commented Nov 1, 2018

@medinarrior Sounds good. Let me know if you run into trouble with them.

@medinarrior
Copy link
Contributor Author

Made changes, let me know if there is more to do :)

@jfuss
Copy link
Contributor

jfuss commented Dec 3, 2018

@medinarrior Taking another pass through this now. Could you rebase when you get a chance? I don't think there should be any conflicts looking at the files.

@medinarrior
Copy link
Contributor Author

@jfuss Not able to see CodeBuild results.

@jfuss
Copy link
Contributor

jfuss commented Dec 3, 2018

@medinarrior Ignore the codebuild. We need to remove it.

jfuss
jfuss previously requested changes Dec 3, 2018
Copy link
Contributor

@jfuss jfuss left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a couple small comments. This looks great and an awesome addition!

@medinarrior
Copy link
Contributor Author

@jfuss Let me know if there is something I need to change :)

@jfuss
Copy link
Contributor

jfuss commented Jan 8, 2019

@medinarrior Appologizes on the time it has taken to look at your update. I am reviewing now.

Copy link
Contributor

@jfuss jfuss left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a small comment/question/discussion point.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you think about logging some information about not fully supporting multiple headers? We would have to print this each time, since we have no idea if the customer is impacted but would result in two things:

  1. It would give the customer some information when invoking (ideally linking out to a Github issue). This could result in less of a "Wait is this me or is this SAM CLI not giving the function the headers".
  2. It would give us (SAM CLI) a way to get feedback on how many customers are impacted by this through the Github Issue +1s.

I know this is current state and I think the only alternative is to rewrite the local service or possibly patch Flask in our implementation so we can support this. I just want to try and avoid the confusion and frustration that may come about from this.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea, what message should be displayed? Agree, it's time to consider patching Flask or rewriting the local service.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe something like:
"WARNING: Multi-value request headers are not fully supported. See issue: for more details."

We would just need to create the issue with some details on how Flask doesn't support this and therefore we currently can't.

Thoughts?

@jfuss
Copy link
Contributor

jfuss commented May 8, 2019

There was a conversation earlier that suggested Flask does not support multiple headers but a recent experiment does show this will work.

from flask import Flask, request
app = Flask(__name__)

@app.route("/")
def hello():
     return "get: " + json.dumps(request.headers.get('Accept')) + "\n" + \
     "get_all: " + json.dumps(request.headers.get_all('Accept')) + "\n" + \
     "getlist: " + json.dumps(request.headers.getlist('Accept')) + "\n" + \
     "environ: " + json.dumps(request.environ['HTTP_ACCEPT']) + "\n"

flask run

Produces:

curl -s http://127.0.0.1:5000 -H'Accept: Working' -H'Accept: Not Working'
get: "Working,Not Working"
get_all: ["Working,Not Working"]
getlist: ["Working,Not Working"]
environ: "Working,Not Working"

Copy link
Contributor

@sriram-mv sriram-mv left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In general this looks good to me. 👍

"resource": self.resource,
"requestContext": request_context_dict,
"queryStringParameters": dict(self.query_string_params) if self.query_string_params else None,
"multiValueQueryStringParameters": dict(self.multi_value_query_string_params)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we need dict(self.multi_value_query_string_params) again? we do validation above to make sure its a dict.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably because someone could mutate the public variable on the object after initializing?

"multiValueQueryStringParameters": dict(self.multi_value_query_string_params)
if self.multi_value_query_string_params else None,
"headers": dict(self.headers) if self.headers else None,
"multiValueHeaders": dict(self.multi_value_headers) if self.multi_value_headers else None,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here

@sanathkr sanathkr dismissed jfuss’s stale review June 6, 2019 22:15

jfuss already reviewed this long back and the feedback has been addressed

@sanathkr sanathkr merged commit 5171db2 into aws:develop Jun 6, 2019
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

Successfully merging this pull request may close these issues.

4 participants