You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
ApiGatewayResolver root routes and strip_prefixes #646
I ran into an issue when using a route with the rule "/" along with strip_prefixes feature. This rule is unable to trigger due to the path variable being reduced down to an empty string instead of a forward slash.
I believe that the common standard among other routing frameworks is that all paths should have a leading slash, so @api.get("/") is usually the root path. Unfortunately the Flask and FastAPI docs don't explicitly state this, though all examples are written this way. I did find this Flask issue describing a related oversight of forgetting to enforce a leading slash though.
As for implementation, Flask and FastAPI both seem to do things differently by building and caching the full paths within each route. However ExpressJS, looks like it handles routing similar to the current ApiGatewayRouter though it does ensure a leading slash.
@BVMiko - agreed. But strip_prefix is supposed to remove the matching prefix from the request.
And that this is on the context of "strip_prefixes" is "/custom-mapping", and the actual request is without a trailing "/" and would look like "/custom-mapping". So naturally I would except the resulting path to be "".
Internally this was not happening due to the addition of a "/" for the starts with check. Because we wanted to allow for "/pay" and "/payment" strip prefixes to be set in any order. As "/pay" would be a partial match. It would remove before "/payment".
So the ultimate solution could just be to reverse the order of the prefixes and remove the "/" we add in the starts with check.
@BVMiko - thinking it through. If the request path resolves to a empty string (""), after the strip prefixes. Then it makes sense that the base is now actually "/".
We just need to document that there is no difference between a request path of "/pay" and "/pay/" when the strip prefix is "/pay".
Activity
michaelbrewer commentedon Aug 23, 2021
Nice one @BVMiko , i put in a review comment for adding a test case.
Otherwise, i was thinking whether it should be
""instead of"/"? Then this would work when the request is/some-pathAs the original request path of
/some-pathdoes different from/some-path/. Although@app.get("")does like strange.BVMiko commentedon Aug 25, 2021
I believe that the common standard among other routing frameworks is that all paths should have a leading slash, so
@api.get("/")is usually the root path. Unfortunately the Flask and FastAPI docs don't explicitly state this, though all examples are written this way. I did find this Flask issue describing a related oversight of forgetting to enforce a leading slash though.As for implementation, Flask and FastAPI both seem to do things differently by building and caching the full paths within each route. However ExpressJS, looks like it handles routing similar to the current ApiGatewayRouter though it does ensure a leading slash.
michaelbrewer commentedon Aug 25, 2021
@BVMiko - agreed. But strip_prefix is supposed to remove the matching prefix from the request.
And that this is on the context of "strip_prefixes" is "/custom-mapping", and the actual request is without a trailing "/" and would look like "/custom-mapping". So naturally I would except the resulting path to be "".
Internally this was not happening due to the addition of a "/" for the starts with check. Because we wanted to allow for "/pay" and "/payment" strip prefixes to be set in any order. As "/pay" would be a partial match. It would remove before "/payment".
So the ultimate solution could just be to reverse the order of the prefixes and remove the "/" we add in the starts with check.
michaelbrewer commentedon Aug 27, 2021
@BVMiko - thinking it through. If the request path resolves to a empty string (""), after the strip prefixes. Then it makes sense that the base is now actually "/".
We just need to document that there is no difference between a request path of "/pay" and "/pay/" when the strip prefix is "/pay".
BVMiko commentedon Aug 31, 2021
@michaelbrewer - I updated the testcase and the docs to reflect the new explicit change; let me know if you'd like the wording modified.
to-mc commentedon Sep 10, 2021
Fixed in v1.20.2.