Skip to content

Commit e35c5f3

Browse files
mxr576dbu
authored andcommitted
Only add path prefix if we did not yet add the prefix on this request
1 parent 7533c2d commit e35c5f3

File tree

2 files changed

+21
-3
lines changed

2 files changed

+21
-3
lines changed

CHANGELOG.md

+6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Change Log
22

3+
## 1.8 (unreleased)
4+
5+
### Changed
6+
7+
- AddPathPlugin no longer add prefix multiple times if a request is restarted - it now only adds the prefix if that request chain has not yet passed through the AddPathPlugin
8+
39
## 1.7.0 - 2017-11-30
410

511
### Added

src/Plugin/AddPathPlugin.php

+15-3
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,9 +46,14 @@ public function __construct(UriInterface $uri)
3946
*/
4047
public function handleRequest(RequestInterface $request, callable $next, callable $first)
4148
{
42-
$request = $request->withUri($request->getUri()
43-
->withPath($this->uri->getPath().$request->getUri()->getPath())
44-
);
49+
$identifier = spl_object_hash((object) $first);
50+
51+
if (!array_key_exists($identifier, $this->alteredRequests)) {
52+
$request = $request->withUri($request->getUri()
53+
->withPath($this->uri->getPath().$request->getUri()->getPath())
54+
);
55+
$this->alteredRequests[$identifier] = $identifier;
56+
}
4557

4658
return $next($request);
4759
}

0 commit comments

Comments
 (0)