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

queryStringParameters set to None when there are no GET parameters #5893

Merged
merged 5 commits into from Apr 21, 2022
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion localstack/services/apigateway/apigateway_listener.py
Expand Up @@ -334,7 +334,7 @@ def apply_request_parameters(
if request_parameters.get(request_param_key, None) == request_param_value:
uri = uri.replace(f"{{{key}}}", path_params[key])

if integration.get("type") != "HTTP_PROXY" and request_parameters:
if integration.get("type") != "HTTP_PROXY" and request_parameters and query_params:
for key in query_params.copy():
request_query_key = f"integration.request.querystring.{key}"
request_param_val = f"method.request.querystring.{key}"
Expand Down
2 changes: 1 addition & 1 deletion localstack/services/apigateway/helpers.py
Expand Up @@ -956,7 +956,7 @@ def extract_query_string_params(path: str) -> Tuple[str, Dict[str, str]]:

# strip trailing slashes from path to fix downstream lookups
path = path.rstrip("/") or "/"
return [path, query_string_params]
return [path, query_string_params or None]


def get_cors_response(headers):
Expand Down
3 changes: 2 additions & 1 deletion localstack/utils/http.py
Expand Up @@ -90,7 +90,8 @@ def add_query_params_to_url(uri: str, query_params: Dict) -> str:
query_dict = dict(parse_qsl(url.query))

# updates the dict with new query parameters
query_dict.update(query_params)
if query_params:
query_dict.update(query_params)

# encodes query parameters
url_query = urlencode(query_dict)
Expand Down
4 changes: 4 additions & 0 deletions tests/unit/test_apigateway.py
Expand Up @@ -30,6 +30,10 @@ def test_extract_query_params(self):
self.assertEqual("/foo/bar", path)
self.assertEqual({"foo": "foo", "bar": ["bar", "baz"]}, query_params)

path, query_params = apigateway_listener.extract_query_string_params("/foo/bar")
self.assertEqual("/foo/bar", path)
self.assertEqual(None, query_params)

def test_extract_path_params(self):
params = apigateway_listener.extract_path_params("/foo/bar", "/foo/{param1}")
self.assertEqual({"param1": "bar"}, params)
Expand Down