Skip to content

Commit

Permalink
Merge pull request #965 from stealthycoin/consistent-local-mode-query…
Browse files Browse the repository at this point in the history
…-args

Make local mode querystring processing consistent with APIGateway
  • Loading branch information
stealthycoin authored Oct 15, 2018
2 parents 91a4ad4 + 7c47fe8 commit 947eb8f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
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

0 comments on commit 947eb8f

Please sign in to comment.