-
Notifications
You must be signed in to change notification settings - Fork 53
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
Dont add path to an url we already added a path to. #141
Conversation
I'll try out this patch next week. IIRC I tried a similar approach before without any luck when I worked on my library. |
that idea makes sense to me. we need to cleanup however, imagine i call the same url repeatedly in the same php process: the rewrite only happens once. with async, i am not sure we can even expect the promise to be resolved already. so we'd need to combine the spl hash and the url, and cleanup in the |
I dont understand, Why would it be any different for async? |
because i could have open promises that have not yet been resolved, and already request the same url again. (yeah, an edge case, but would be good to not fail on edge cases this time) |
I still dont understand. Im sorry. If i add the path T0: An async request (A) to https://example.com/foo T3: A normal request (C) to https://example.com/api/foo T5: Request (A) will be resolved and rewritten to https://example.com/api/foo Issue. T4 and T7. Same would happen if: T0: A normal request (A) to https://example.com/api/foo T2: A normal request (B) to https://example.com/foo T4: A normal request (C) to https://example.com/api/foo I mean, async or not does not matter. |
The issue above is acceptable. My PR make sure we never add /api/v1` twice. The issue I describe is an edge case that will only happen if:
A is just using the plugin wrong. |
the current code will fail when we do
The first time, we add the prefix, the second time we don't. The plugin is not reset on each request. If we add a
|
No, I think you are reading the code wrong. I removed a test that was not working that probably confused you. |
I added a PHP unit test to prove that Im correct. My PHPspec knowledge is too poor. If anyone wants to write write my phpunit test to phpspec, then be my guest. |
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.
sorry, i indeed missed that we now store the resulting url, not what we had as a starting point. that makes more sense, but i still think its problematic. in your test example with /api it would indeed be very strange to repeat the prefix, but i am sure somebody will have a situation where they expect the prefix to be added.
with your change, we depend on the order of how requests have been executed. if we say we do not want to support the case of the prefix being the same as the start of the supplied path, i think it would be better to check if the prefix is already present, as that would lead to context-free behaviour.
imho we can chose between:
given the scenarios and use cases, i think a) is better. with b), there is also the issue that retry would be broken if redirecting comes after the retry plugin. a) will also work fine with redirects, as those most likely already have the right prefix. |
I would also go with option a. It covers 98% of the use cases ( |
Sure! Let's do that! |
I've updated the PR |
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.
cool, thanks!
lets also update the documentation a bit to well explain the edge case where this now does not work as expected.
CHANGELOG.md
Outdated
and `delay` to `exception_delay`. The old names still work but are deprecated. | ||
- AddPathPlugin does not add prefix if the prefix already is defined. |
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.
maybe: "AddPathPlugin: Do not add the prefix if the URL already has the same prefix."
How about this? |
There is no documentation :/ |
use PHPUnit\Framework\TestCase; | ||
use Psr\Http\Message\RequestInterface; | ||
|
||
class AddPathPluginTest extends TestCase |
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 think we can simplify this test a lot now.
found it here: https://github.com/php-http/documentation/blob/master/plugins/request-uri-manipulations.rst |
I rebased this PR on 2.x |
documentation: php-http/documentation#245 |
Good job guys. 👏 |
thanks. this was really tricky - and i think we came full circle on the approach we use... |
# Conflicts: # CHANGELOG.md # src/Plugin/AddPathPlugin.php
What's in this PR?
What if we stored all the results of our rewrite and make sure we never rewrite a url that were stored as a result?