Skip to content

fixes multivalue query param requests for HTTP APIs#3365

Closed
jlapier wants to merge 1 commit intoaws:developfrom
Field-Day-CI:fix_multivalue_query_params_http
Closed

fixes multivalue query param requests for HTTP APIs#3365
jlapier wants to merge 1 commit intoaws:developfrom
Field-Day-CI:fix_multivalue_query_params_http

Conversation

@jlapier
Copy link
Contributor

@jlapier jlapier commented Oct 15, 2021

When a query parameter is specified multiple times in a URL, e.g.
path?mykey=1&mykey=2&mykey=3
this should create an event with all appropriate values.

Prior to this commit, when using sam local start-api with an HTTP API, only the first value is present in the queryStringParameters of the event. In payload format v2 used in HTTP APIs, multiple values should be combined with commas and included in the queryStringParameters field. This commit fixes the behavior for query string parameters.

Which issue(s) does this change fix?

#3194

Why is this change necessary?

The local API does not match the behavior of an HTTP API in API Gateway.

How does it address the issue?

It formats multivalue query parameters per the payload format version 2.

What side effects does this change have?

Previously truncated query parameter values will be included in the queryStringParameters field of an event.

Checklist

  • Add input/output type hints to new functions/methods
  • Write design document (Do I need to write a design document?)
  • Write unit tests
  • Write/update functional tests
  • Write/update integration tests
  • make pr passes
  • make update-reproducible-reqs if dependencies were changed
  • Write documentation

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

When a query parameter is specified multiple times in a URL, e.g.
`path?mykey=1&mykey=2&mykey=3`
this should create an event with all appropriate values.

Prior to this commit, when using `sam local start-api` with an HTTP API,
only the first value is present in the queryStringParameters of the
event. In payload format v2 [1] used in HTTP APIs, multiple values
should be combined with commas and included in the queryStringParameters
field. This commit fixes the behavior for query string parameters.

[1] https://docs.aws.amazon.com/apigateway/latest/developerguide/http-api-develop-integrations-lambda.html
Copy link
Contributor

@hawflau hawflau left a comment

Choose a reason for hiding this comment

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

Thanks for the contribution! Just left two comments. Can you also please check the check failures and fix the merge conflict?

# Flask returns an ImmutableMultiDict so convert to a dictionary that becomes
# a dict(str: list) then iterate over
for query_string_key, query_string_list in flask_request.args.lists():
query_string_value_length = len(query_string_list)
Copy link
Contributor

Choose a reason for hiding this comment

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

it would be better to just keep the last line of L848-L854, i.e.

query_string_dict[query_string_key] = ",".join(query_string_list)

",".join(query_string_list) returns an empty string if query_string_list is an empty list.

Or, we could make the entire function even shorter:

query_string_dict = {
    query_string_key: ",".join(query_string_list)
    for query_string_key, query_string_list in flask_request.args.lists()
}
return query_string_dict

self.request_mock.mimetype = "application/json"
query_param_args_mock = Mock()
query_param_args_mock.lists.return_value = {"query": ["params"]}.items()
query_param_args_mock.lists.return_value = {"query": ["param1","param2"]}.items()
Copy link
Contributor

Choose a reason for hiding this comment

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

you can run make black to fix the formatting issue here

@hawflau
Copy link
Contributor

hawflau commented Mar 31, 2022

Closing due to no response. I re-submitted a new one (#3788) to resolve merge conflicts, apply recommendations and add one more test.

@hawflau hawflau closed this Mar 31, 2022
@jlapier
Copy link
Contributor Author

jlapier commented Apr 1, 2022

Thanks for following up on this @hawflau! My apologies for being unable to find the time to respond to feedback.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants