Skip to content

Commit 8870ced

Browse files
authored
Make sure the path prefix is actually present even if the request has been altered before
Follow up on php-http#103. Everything worked fine until I refactored my tests and started to use a singleton API client for offline testing. If I call the same API endpoints in the same test with the client then the first API request gets prefixed properly but the second one does not, because the generated `$identifier` is already exist in the ` $this->alteredRequests`. I tried to use something else for identifier, I tried different ways to make the identifier more unique but I could not figure out a better solution than this for s start.
1 parent 5496bf2 commit 8870ced

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

src/Plugin/AddPathPlugin.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public function handleRequest(RequestInterface $request, callable $next, callabl
4848
{
4949
$identifier = spl_object_hash((object) $first);
5050

51-
if (!array_key_exists($identifier, $this->alteredRequests)) {
51+
if (!array_key_exists($identifier, $this->alteredRequests) || strpos($request->getUri()->getPath(), $this->uri->getPath()) !== 0) {
5252
$request = $request->withUri($request->getUri()
5353
->withPath($this->uri->getPath().$request->getUri()->getPath())
5454
);

0 commit comments

Comments
 (0)