diff --git a/lib/Github/HttpClient/Plugin/PathPrepend.php b/lib/Github/HttpClient/Plugin/PathPrepend.php index 567bb156ed7..2c91bf74f3b 100644 --- a/lib/Github/HttpClient/Plugin/PathPrepend.php +++ b/lib/Github/HttpClient/Plugin/PathPrepend.php @@ -30,10 +30,9 @@ public function handleRequest(RequestInterface $request, callable $next, callabl $currentPath = $request->getUri()->getPath(); if (strpos($currentPath, $this->path) !== 0) { $uri = $request->getUri()->withPath($this->path.$currentPath); + $request = $request->withUri($uri); } - $request = $request->withUri($uri); - return $next($request); } } diff --git a/test/Github/Tests/HttpClient/PathPrependTest.php b/test/Github/Tests/HttpClient/PathPrependTest.php new file mode 100644 index 00000000000..dbd7905c739 --- /dev/null +++ b/test/Github/Tests/HttpClient/PathPrependTest.php @@ -0,0 +1,39 @@ + + */ +class PathPrependTest extends TestCase +{ + /** + * @dataProvider uris + */ + public function testPathIsPrepended($uri, $expectedPath) + { + $request = new Request('GET', $uri); + $plugin = new PathPrepend('/api/v3'); + + $newRequest = null; + $plugin->handleRequest($request, function ($request) use (&$newRequest) { + $newRequest = $request; + }, function () { + throw new \RuntimeException("Did not expect plugin to call first"); + }); + + $this->assertEquals($expectedPath, $newRequest->getUri()->getPath()); + } + + public static function uris() + { + return [ + ['http://example.com/foo/bar/api', '/api/v3/foo/bar/api'], + ['http://example.com/api/v3/foo/bar/api', '/api/v3/foo/bar/api'], + ]; + } +}