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)
46
46
*/
47
47
public function handleRequest (RequestInterface $ request , callable $ next , callable $ first )
48
48
{
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
+ }
60
57
61
58
return $ next ($ request );
62
59
}
Original file line number Diff line number Diff line change @@ -89,7 +89,7 @@ public function testRewriteWithDifferentUrlWhenSecondUrlIncludesAddedPath()
89
89
public function testRewriteWhenPathIsIncluded ()
90
90
{
91
91
$ 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 ());
93
93
};
94
94
95
95
$ request = new Request ('GET ' , 'https://example.com/api/foo ' );
You can’t perform that action at this time.
0 commit comments