File tree Expand file tree Collapse file tree 2 files changed +9
-12
lines changed Expand file tree Collapse file tree 2 files changed +9
-12
lines changed Original file line number Diff line number Diff line change @@ -46,17 +46,14 @@ public function __construct(UriInterface $uri)
4646 */
4747 public function handleRequest (RequestInterface $ request , callable $ next , callable $ first )
4848 {
49- // Use the request URI as an identifier
50- $ identifier = sha1 ((string ) $ request ->getUri ());
51-
52- // If the current URL is a result of a previous rewrite, then do nothing.
53- if (!array_key_exists ($ identifier , $ this ->alteredRequests )) {
54- $ prefixedUri = $ request ->getUri ()->withPath ($ this ->uri ->getPath ().$ request ->getUri ()->getPath ());
55- $ request = $ request ->withUri ($ prefixedUri );
56-
57- // Store for future checks
58- $ this ->alteredRequests [sha1 ((string ) $ prefixedUri )] = true ;
59- }
49+ $ prepend = $ this ->uri ->getPath ();
50+ $ path = $ request ->getUri ()->getPath ();
51+
52+ if (substr ($ path , 0 , strlen ($ prepend )) !== $ prepend ) {
53+ $ request = $ request ->withUri ($ request ->getUri ()
54+ ->withPath ($ prepend .$ path )
55+ );
56+ }
6057
6158 return $ next ($ request );
6259 }
Original file line number Diff line number Diff line change @@ -89,7 +89,7 @@ public function testRewriteWithDifferentUrlWhenSecondUrlIncludesAddedPath()
8989 public function testRewriteWhenPathIsIncluded ()
9090 {
9191 $ verify = function (RequestInterface $ request ) {
92- $ this ->assertEquals ('https://example.com/api/api/ foo ' , $ request ->getUri ()->__toString ());
92+ $ this ->assertEquals ('https://example.com/api/foo ' , $ request ->getUri ()->__toString ());
9393 };
9494
9595 $ request = new Request ('GET ' , 'https://example.com/api/foo ' );
You can’t perform that action at this time.
0 commit comments