Skip to content

Commit 4a962c6

Browse files
authored
Merge pull request #221 from php-http/fix-redirect-host
redirection to different domain must not keep previous port
2 parents 76730e3 + 509e513 commit 4a962c6

19 files changed

+108
-76
lines changed

.github/workflows/static.yml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ name: static
22

33
on:
44
push:
5+
branches:
6+
- master
57
pull_request:
68

79
jobs:
@@ -19,3 +21,16 @@ jobs:
1921
REQUIRE_DEV: false
2022
with:
2123
args: analyze --no-progress
24+
25+
php-cs-fixer:
26+
name: PHP-CS-Fixer
27+
runs-on: ubuntu-latest
28+
29+
steps:
30+
- name: Checkout code
31+
uses: actions/checkout@v2
32+
33+
- name: PHP-CS-Fixer
34+
uses: docker://oskarstark/php-cs-fixer-ga
35+
with:
36+
args: --dry-run --diff

.github/workflows/tests.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ name: tests
22

33
on:
44
push:
5+
branches:
6+
- master
57
pull_request:
68

79
jobs:

.gitignore

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
/.php_cs
2-
/.php_cs.cache
1+
/.php-cs-fixer.php
2+
/.php-cs-fixer.cache
33
/behat.yml
44
/build/
55
/composer.lock

.php-cs-fixer.dist.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
3+
$finder = PhpCsFixer\Finder::create()
4+
->in(__DIR__.'/src')
5+
->in(__DIR__.'/tests')
6+
->name('*.php')
7+
;
8+
9+
$config = new PhpCsFixer\Config();
10+
11+
return $config
12+
->setRiskyAllowed(true)
13+
->setRules([
14+
'@Symfony' => true,
15+
'single_line_throw' => false,
16+
])
17+
->setFinder($finder)
18+
;

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44

55
### Fixed
66

7-
- Fixes false positive circular detection in RedirectPlugin in cases when target location does not contain path
7+
- [RedirectPlugin] Fixed handling of redirection to different domain with default port
8+
- [RedirectPlugin] Fixed false positive circular detection in RedirectPlugin in cases when target location does not contain path
89

910
## 2.5.0 - 2021-11-26
1011

spec/Plugin/RedirectPluginSpec.php

Lines changed: 0 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -506,54 +506,4 @@ public function it_throws_circular_redirection_exception_on_alternating_redirect
506506
$promise->shouldReturnAnInstanceOf(HttpRejectedPromise::class);
507507
$promise->shouldThrow(CircularRedirectionException::class)->duringWait();
508508
}
509-
510-
public function it_redirects_http_to_https(
511-
UriInterface $uri,
512-
UriInterface $uriRedirect,
513-
RequestInterface $request,
514-
ResponseInterface $responseRedirect,
515-
RequestInterface $modifiedRequest,
516-
ResponseInterface $finalResponse,
517-
Promise $promise
518-
) {
519-
$responseRedirect->getStatusCode()->willReturn(302);
520-
$responseRedirect->hasHeader('Location')->willReturn(true);
521-
$responseRedirect->getHeaderLine('Location')->willReturn('https://my-site.com/original');
522-
523-
$request->getUri()->willReturn($uri);
524-
$request->withUri($uriRedirect)->willReturn($modifiedRequest);
525-
$uri->__toString()->willReturn('http://my-site.com/original');
526-
$uri->withPath('/original')->willReturn($uri);
527-
$uri->withFragment('')->willReturn($uri);
528-
$uri->withQuery('')->willReturn($uri);
529-
530-
$uri->withScheme('https')->willReturn($uriRedirect);
531-
$uriRedirect->withHost('my-site.com')->willReturn($uriRedirect);
532-
$uriRedirect->withPath('/original')->willReturn($uriRedirect);
533-
$uriRedirect->withFragment('')->willReturn($uriRedirect);
534-
$uriRedirect->withQuery('')->willReturn($uriRedirect);
535-
$uriRedirect->__toString()->willReturn('https://my-site.com/original');
536-
537-
$modifiedRequest->getUri()->willReturn($uriRedirect);
538-
$modifiedRequest->getMethod()->willReturn('GET');
539-
540-
$next = function (RequestInterface $receivedRequest) use ($request, $responseRedirect) {
541-
if (Argument::is($request->getWrappedObject())->scoreArgument($receivedRequest)) {
542-
return new HttpFulfilledPromise($responseRedirect->getWrappedObject());
543-
}
544-
};
545-
546-
$first = function (RequestInterface $receivedRequest) use ($modifiedRequest, $promise) {
547-
if (Argument::is($modifiedRequest->getWrappedObject())->scoreArgument($receivedRequest)) {
548-
return $promise->getWrappedObject();
549-
}
550-
};
551-
552-
$promise->getState()->willReturn(Promise::FULFILLED);
553-
$promise->wait()->shouldBeCalled()->willReturn($finalResponse);
554-
555-
$finalPromise = $this->handleRequest($request, $next, $first);
556-
$finalPromise->shouldReturnAnInstanceOf(HttpFulfilledPromise::class);
557-
$finalPromise->wait()->shouldReturn($finalResponse);
558-
}
559509
}

src/Deferred.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,10 @@ public function wait($unwrap = true)
146146
return $this->value;
147147
}
148148

149-
/** @var ClientExceptionInterface */
149+
if (null === $this->failure) {
150+
throw new \RuntimeException('Internal Error: Promise is not fulfilled but has no exception stored');
151+
}
152+
150153
throw $this->failure;
151154
}
152155
}

src/HttpClientPool/HttpClientPool.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,9 @@ public function addHttpClient($client): void
4646
/**
4747
* Return an http client given a specific strategy.
4848
*
49-
* @throws HttpClientNotFoundException When no http client has been found into the pool
50-
*
5149
* @return HttpClientPoolItem Return a http client that can do both sync or async
50+
*
51+
* @throws HttpClientNotFoundException When no http client has been found into the pool
5252
*/
5353
abstract protected function chooseHttpClient(): HttpClientPoolItem;
5454

src/Plugin/AddHostPlugin.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ final class AddHostPlugin implements Plugin
3131
* @param array{'replace'?: bool} $config
3232
*
3333
* Configuration options:
34-
* - replace: True will replace all hosts, false will only add host when none is specified.
34+
* - replace: True will replace all hosts, false will only add host when none is specified
3535
*/
3636
public function __construct(UriInterface $host, array $config = [])
3737
{

src/Plugin/AddPathPlugin.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ public function handleRequest(RequestInterface $request, callable $next, callabl
7070
if (substr($path, 0, strlen($prepend)) !== $prepend) {
7171
$request = $request->withUri($request->getUri()
7272
->withPath($prepend.$path)
73-
);
73+
);
7474
}
7575

7676
return $next($request);

0 commit comments

Comments
 (0)