Skip to content

Commit

Permalink
Only add path prefix if we did not yet add the prefix on this request
Browse files Browse the repository at this point in the history
  • Loading branch information
mxr576 authored and dbu committed May 26, 2018
1 parent 7533c2d commit e35c5f3
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Change Log

## 1.8 (unreleased)

### Changed

- 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

## 1.7.0 - 2017-11-30

### Added
Expand Down
18 changes: 15 additions & 3 deletions src/Plugin/AddPathPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,13 @@ final class AddPathPlugin implements Plugin
*/
private $uri;

/**
* Stores identifiers of the already altered requests.
*
* @var array
*/
private $alteredRequests = [];

/**
* @param UriInterface $uri
*/
Expand All @@ -39,9 +46,14 @@ public function __construct(UriInterface $uri)
*/
public function handleRequest(RequestInterface $request, callable $next, callable $first)
{
$request = $request->withUri($request->getUri()
->withPath($this->uri->getPath().$request->getUri()->getPath())
);
$identifier = spl_object_hash((object) $first);

if (!array_key_exists($identifier, $this->alteredRequests)) {
$request = $request->withUri($request->getUri()
->withPath($this->uri->getPath().$request->getUri()->getPath())
);
$this->alteredRequests[$identifier] = $identifier;
}

return $next($request);
}
Expand Down

0 comments on commit e35c5f3

Please sign in to comment.