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

Make local mode querystring processing consistent with APIGateway #965

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion chalice/local.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ def match_route(self, url):
# Otherwise we need to check for param substitution
parsed_url = urlparse(url)
parsed_qs = parse_qs(parsed_url.query, keep_blank_values=True)
query_params = {k: v[0] for k, v in parsed_qs.items()}
query_params = {k: v[-1] for k, v in parsed_qs.items()}
path = parsed_url.path
# API Gateway removes the trailing slash if the route is not the root
# path. We do the same here so our route matching works the same way.
Expand Down
8 changes: 8 additions & 0 deletions tests/unit/test_local.py
Original file line number Diff line number Diff line change
Expand Up @@ -462,6 +462,14 @@ def test_querystring_is_mapped(handler):
assert _get_body_from_response_stream(handler) == {'a': 'b', 'c': 'd'}


def test_querystring_undefined_is_mapped_consistent_with_apigateway(handler):
# API Gateway picks up the last element of duplicate keys in a
# querystring
set_current_request(handler, method='GET', path='/query-string?a=b&a=c')
handler.do_GET()
assert _get_body_from_response_stream(handler) == {'a': 'c'}


def test_content_type_included_once(handler):
set_current_request(handler, method='GET', path='/custom-response')
handler.do_GET()
Expand Down