Skip to content

Commit fa291ea

Browse files
dbuNyholm
authored andcommitted
AddHostPlugin must also handle the port (#29)
1 parent 39831c4 commit fa291ea

File tree

3 files changed

+15
-4
lines changed

3 files changed

+15
-4
lines changed

CHANGELOG.md

+5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# Change Log
22

3+
## Unreleased
4+
5+
### Changed
6+
7+
- AddHostPlugin also sets the port if specified
38

49
## 1.2.0 - 2016-07-14
510

spec/Plugin/AddHostPluginSpec.php

+4-1
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,14 @@ function it_adds_domain(
3939
) {
4040
$host->getScheme()->shouldBeCalled()->willReturn('http://');
4141
$host->getHost()->shouldBeCalled()->willReturn('example.com');
42+
$host->getPort()->shouldBeCalled()->willReturn(8000);
4243

4344
$request->getUri()->shouldBeCalled()->willReturn($uri);
4445
$request->withUri($uri)->shouldBeCalled()->willReturn($request);
4546

4647
$uri->withScheme('http://')->shouldBeCalled()->willReturn($uri);
4748
$uri->withHost('example.com')->shouldBeCalled()->willReturn($uri);
49+
$uri->withPort(8000)->shouldBeCalled()->willReturn($uri);
4850
$uri->getHost()->shouldBeCalled()->willReturn('');
4951

5052
$this->beConstructedWith($host);
@@ -58,13 +60,14 @@ function it_replaces_domain(
5860
) {
5961
$host->getScheme()->shouldBeCalled()->willReturn('http://');
6062
$host->getHost()->shouldBeCalled()->willReturn('example.com');
63+
$host->getPort()->shouldBeCalled()->willReturn(8000);
6164

6265
$request->getUri()->shouldBeCalled()->willReturn($uri);
6366
$request->withUri($uri)->shouldBeCalled()->willReturn($request);
6467

6568
$uri->withScheme('http://')->shouldBeCalled()->willReturn($uri);
6669
$uri->withHost('example.com')->shouldBeCalled()->willReturn($uri);
67-
70+
$uri->withPort(8000)->shouldBeCalled()->willReturn($uri);
6871

6972
$this->beConstructedWith($host, ['replace' => true]);
7073
$this->handleRequest($request, function () {}, function () {});

src/Plugin/AddHostPlugin.php

+6-3
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
use Symfony\Component\OptionsResolver\OptionsResolver;
99

1010
/**
11-
* Add schema and host to a request. Can be set to overwrite the schema and host if desired.
11+
* Add schema, host and port to a request. Can be set to overwrite the schema and host if desired.
1212
*
1313
* @author Tobias Nyholm <[email protected]>
1414
*/
@@ -52,8 +52,11 @@ public function __construct(UriInterface $host, array $config = [])
5252
public function handleRequest(RequestInterface $request, callable $next, callable $first)
5353
{
5454
if ($this->replace || $request->getUri()->getHost() === '') {
55-
$uri = $request->getUri()->withHost($this->host->getHost());
56-
$uri = $uri->withScheme($this->host->getScheme());
55+
$uri = $request->getUri()
56+
->withHost($this->host->getHost())
57+
->withScheme($this->host->getScheme())
58+
->withPort($this->host->getPort())
59+
;
5760

5861
$request = $request->withUri($uri);
5962
}

0 commit comments

Comments
 (0)