-
Notifications
You must be signed in to change notification settings - Fork 488
Adds non greedy parameter values into the path when {proxy+} #1403
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
Adds non greedy parameter values into the path when {proxy+} #1403
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This for this bug fix. We also need some tests for this fix. Tests for this project are here and are relatively easy to add. Basically just create your sample event json and a corresponding endpoint in the test project.
@@ -154,12 +154,21 @@ protected override void MarshallRequest(InvokeFeatures features, APIGatewayProxy | |||
requestFeatures.Method = apiGatewayRequest.HttpMethod; | |||
|
|||
string path = null; | |||
|
|||
// Replaces {proxy+} in path, if exists |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems like we should always be doing this logic regardless over the being a {proxy+}
. It is possible to use this package and not use {proxy+}
and use path parameters..
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That is a good point actually. Let me double check the case and I'll update the PR, if required.
As far as this PR goes, we have been using a custom build of the package across multiple APIs, with the changes in the PR since December 24th, and it all works as expected (cases are normal proxy resources without non-greedy parameters, non-proxy resources without non-greedy parameters and proxy resources with non-greedy parameters).
I have found that replacing the logic in lines 156-171 with string path = apiGatewayRequest.Path;
at line 156 causes some tests to fail, so for now, it's easier/safer to use the logic in this PR, in my opinion, as all tests succeed, and it's been tested on (our) production for a good while, without issues.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I double checked and we are actually also using non-greedy parameters in non-proxy resource paths in our custom deployments that contain this PR.
This works just fine because the path does never get in the {proxy+} logic (line 157 on) and gets replaced properly by line 175
if (string.IsNullOrEmpty(path))
{
path = apiGatewayRequest.Path;
}
I have added an additional test to cover this case, and it passes without any modifications to the PR
Thanks for the PR. The PR has been released as part of version 8.0.0 of Amazon.Lambda.AspNetCoreServer. This was a major version bump to PR #899 shipped in this release which is a slight breaking change. |
Issue #, if available:
#1233
A confirmed bug since July, that has not been fixed yet, and has taken me a whole day until I realised what the problem is.
Basically, when {proxy+}, the values of the non-greedy parameters are not picked up from the request path.
So the following scenario fails:
Given an API Gateway resource set up as
/path/{foo}/bar/{proxy+}
When I make a request to path
/path/afoo/bar/subpath
Then the
foo
variable in my controller action should be equal toafoo
What actually happens is that my controller's
foo
variable contains the value{foo}
Description of changes:
Added code that will actually replace the non-greedy parameters with their values in the path.
In order to keep changes as small as possible, I just added a loop, but I think it would be better optimised if the path was replaced straight away with the incoming request's path - that's already what happens with non-proxy requests ((line 176). I added a comment about that.
The pull request refers to lines
156-177
ofApiGatewayProxyFunction.cs
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.