Skip to content

Commit c34a2c9

Browse files
committed
Hash requests to prevent multiple alteration of the same request.
1 parent 7a0034c commit c34a2c9

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

src/Plugin/AddPathPlugin.php

+11-1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,13 @@ final class AddPathPlugin implements Plugin
1818
*/
1919
private $uri;
2020

21+
/**
22+
* Stores identifiers of the already altered requests.
23+
*
24+
* @var array
25+
*/
26+
private $alteredRequests = [];
27+
2128
/**
2229
* @param UriInterface $uri
2330
*/
@@ -39,10 +46,13 @@ public function __construct(UriInterface $uri)
3946
*/
4047
public function handleRequest(RequestInterface $request, callable $next, callable $first)
4148
{
42-
if (0 !== strpos($request->getUri()->getPath(), $this->uri->getPath())) {
49+
$identifier = spl_object_hash((object) $first);
50+
51+
if (!in_array($identifier, $this->alteredRequests)) {
4352
$request = $request->withUri($request->getUri()
4453
->withPath($this->uri->getPath().$request->getUri()->getPath())
4554
);
55+
$this->alteredRequests[] = $identifier;
4656
}
4757

4858
return $next($request);

0 commit comments

Comments
 (0)