diff --git a/CHANGELOG.md b/CHANGELOG.md index 87fc0d3..c2ced46 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,10 @@ # Change Log +## Unreleased + +### Changed + +- AddHostPlugin also sets the port if specified ## 1.2.0 - 2016-07-14 diff --git a/spec/Plugin/AddHostPluginSpec.php b/spec/Plugin/AddHostPluginSpec.php index 9df6248..a3fb2d6 100644 --- a/spec/Plugin/AddHostPluginSpec.php +++ b/spec/Plugin/AddHostPluginSpec.php @@ -39,12 +39,14 @@ function it_adds_domain( ) { $host->getScheme()->shouldBeCalled()->willReturn('http://'); $host->getHost()->shouldBeCalled()->willReturn('example.com'); + $host->getPort()->shouldBeCalled()->willReturn(8000); $request->getUri()->shouldBeCalled()->willReturn($uri); $request->withUri($uri)->shouldBeCalled()->willReturn($request); $uri->withScheme('http://')->shouldBeCalled()->willReturn($uri); $uri->withHost('example.com')->shouldBeCalled()->willReturn($uri); + $uri->withPort(8000)->shouldBeCalled()->willReturn($uri); $uri->getHost()->shouldBeCalled()->willReturn(''); $this->beConstructedWith($host); @@ -58,13 +60,14 @@ function it_replaces_domain( ) { $host->getScheme()->shouldBeCalled()->willReturn('http://'); $host->getHost()->shouldBeCalled()->willReturn('example.com'); + $host->getPort()->shouldBeCalled()->willReturn(8000); $request->getUri()->shouldBeCalled()->willReturn($uri); $request->withUri($uri)->shouldBeCalled()->willReturn($request); $uri->withScheme('http://')->shouldBeCalled()->willReturn($uri); $uri->withHost('example.com')->shouldBeCalled()->willReturn($uri); - + $uri->withPort(8000)->shouldBeCalled()->willReturn($uri); $this->beConstructedWith($host, ['replace' => true]); $this->handleRequest($request, function () {}, function () {}); diff --git a/src/Plugin/AddHostPlugin.php b/src/Plugin/AddHostPlugin.php index 021554e..9e35de2 100644 --- a/src/Plugin/AddHostPlugin.php +++ b/src/Plugin/AddHostPlugin.php @@ -8,7 +8,7 @@ use Symfony\Component\OptionsResolver\OptionsResolver; /** - * Add schema and host to a request. Can be set to overwrite the schema and host if desired. + * Add schema, host and port to a request. Can be set to overwrite the schema and host if desired. * * @author Tobias Nyholm */ @@ -52,8 +52,11 @@ public function __construct(UriInterface $host, array $config = []) public function handleRequest(RequestInterface $request, callable $next, callable $first) { if ($this->replace || $request->getUri()->getHost() === '') { - $uri = $request->getUri()->withHost($this->host->getHost()); - $uri = $uri->withScheme($this->host->getScheme()); + $uri = $request->getUri() + ->withHost($this->host->getHost()) + ->withScheme($this->host->getScheme()) + ->withPort($this->host->getPort()) + ; $request = $request->withUri($uri); }