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

Query parameter values not URL decoded when using a RequestStreamHandler implementation #1089

Merged
merged 9 commits into from
Nov 27, 2024

Conversation

jpfennelly
Copy link
Contributor

Issue #, if available: 976

Description of changes:

  • Fixed AwsProxyRequestBuilder, used by unit tests, to be immutable when calling the alb() method. Previously, a call to the alb() method would encode query parameters, modifying the state of the builder. Subsequent usage of the builder for non-ALB unit tests would use the now-encoded query parameters. This wasn't an issue in current current tests because no tests were testing query param decoding. Added unit tests for the builder class itself.
  • Additional unit tests and cleanup to separate form param from query param constants in tests
  • Added overloaded generateParameterMap() method that takes a flag to determine if it should decode query parameters so that functionality for ALB and non-ALB requests can be supported
  • Updated unit tests to test encoded query parameter names and values
  • Update HTTP request methods for parameters to handle decoding for ALB requests
  • Updated HTTP API V2 request to correctly decode values

By submitting this pull request

  • I confirm that my contribution is made under the terms of the Apache 2.0 license.
  • I confirm that I've made a best effort attempt to update all relevant documentation.

Copy link
Contributor

@valerena valerena 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 very detailed PR. I added a couple of minor comments.

Also something that wasn't clear to me is: if the problem is with API GW V2, then why are there changes related to ALB too? Is there a separate bug with ALB encoding as well? Or is it related to the same issue?

}

// decode all keys and values in map
Copy link
Contributor

Choose a reason for hiding this comment

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

It's a fairly minor thing, but all this new code has a mix of spaces and tabs (first indentation is 4 spaces, then only tabs). Even though the project has some files with a mix of both, the vast majority of files are using spaces only. So try to keep this one with spaces only too. (The tests added are also using tabs, and hopefully you can change them to spaces)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

😱 ... fixed, everything is spaces now

List<String> values = new ArrayList<>(Arrays.asList(getQueryParamValues(request.getMultiValueQueryStringParameters(), s, config.isQueryStringCaseSensitive())));
// List<String> values = getQueryParamValuesAsList(request.getMultiValueQueryStringParameters(), s, config.isQueryStringCaseSensitive());
Copy link
Contributor

Choose a reason for hiding this comment

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

I imagine this comment shouldn't be here

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I also had a todo around cleaning up the conversions between arrays and lists happening here and the getQueryParamValues() method. This should be a little better with some extra null safety now and the commented code has been removed.

@jpfennelly
Copy link
Contributor Author

Also something that wasn't clear to me is: if the problem is with API GW V2, then why are there changes related to ALB too? Is there a separate bug with ALB encoding as well? Or is it related to the same issue?

As I began fixing the unit tests and adding tests for query param encoding/decoding, it revealed that the handling of encoded query params had issues in other areas as well. So this bug did expand into fixing query param encoding across all of the integration types.

@jpfennelly jpfennelly force-pushed the 976-query-params-not-urldecoded branch from feff940 to a202873 Compare November 25, 2024 20:15
queryStringParams = decodedQs;
} else {
// If it's case insensitive, we check the entire map on every parameter
queryStringParams = decodedQs.entrySet().stream().collect(
Copy link
Contributor

Choose a reason for hiding this comment

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

Any reason to remove this parallel here?

I'm not sure how much it actually helps, but this has been used since the first versions of this, so I'm curious if you had a specific reason to remove it.

Copy link
Collaborator

Choose a reason for hiding this comment

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

reintroduced it for now

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Parallel streams actually perform worse than a sequential stream for small stream data sets due to the work involved in splitting up the data set, farming them out to threads, then recombining the results. Here's an article: https://blogs.oracle.com/javamagazine/post/java-parallel-streams-performance-benchmark.

And because I come from the old days where we had to get every last drop out of available memory and CPU because there was no magical cloud scaling :) So it's an old habit to be searching for these types of efficiency gains. I also reworked some usage in getQueryParameters() where arrays and lists were being created and immediately disposed of.

It's not a big deal in the end, but it's a good one to know. Parallel is not always the silver bullet it seems to be.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Thanks for sharing - makes sense! If @valerena agrees, we can address that for 2.1.1, I just didn't want to delay the 2.1.0 release any longer.

@deki deki changed the title Query parameter values not URL decoded when using HTTP API V2 Gateway with a RequestStreamHandler implementation Query parameter values not URL decoded when using a RequestStreamHandler implementation Nov 27, 2024
@deki deki merged commit a8ac356 into aws:main Nov 27, 2024
4 checks passed
@deki
Copy link
Collaborator

deki commented Nov 27, 2024

Thank you very much for your contribution, @jpfennelly. Will be part of the 2.1.0 release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants