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

Parse and pass through query string params in local mode #184

Merged
merged 1 commit into from
Dec 27, 2016
Merged
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
15 changes: 11 additions & 4 deletions chalice/local.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,13 @@
from chalice.app import Chalice # noqa
from typing import List, Any, Dict, Tuple, Callable # noqa

try:
from urllib.parse import urlparse, parse_qs
except ImportError:
from urlparse import urlparse, parse_qs

MatchResult = namedtuple('MatchResult', ['route', 'captured'])

MatchResult = namedtuple('MatchResult', ['route', 'captured', 'query_params'])
EventType = Dict[str, Any]
HandlerCls = Callable[..., 'ChaliceRequestHandler']
ServerCls = Callable[..., 'HTTPServer']
Expand Down Expand Up @@ -44,7 +49,9 @@ def match_route(self, url):

"""
# Otherwise we need to check for param substitution
parts = url.split('/')
parsed_url = urlparse(url)
query_params = {k: v[0] for k, v in parse_qs(parsed_url.query).items()}
parts = parsed_url.path.split('/')
captured = {}
for route_url in self.route_urls:
url_parts = route_url.split('/')
Expand All @@ -56,7 +63,7 @@ def match_route(self, url):
if i != j:
break
else:
return MatchResult(route_url, captured)
return MatchResult(route_url, captured, query_params)
raise ValueError("No matching route found for: %s" % url)


Expand Down Expand Up @@ -84,7 +91,7 @@ def create_lambda_event(self, method, path, headers, body=None):
'params': {
'header': dict(headers),
'path': view_route.captured,
'querystring': {},
'querystring': view_route.query_params,
},
'body-json': json_body,
'base64-body': base64_body,
Expand Down