Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 981a11b

Browse filesBrowse files
dmolineusfabpot
authored andcommitted
[HttpKernel] Do not override max_redirects option in HttpClientKernel
1 parent cae08a0 commit 981a11b
Copy full SHA for 981a11b

File tree

Expand file treeCollapse file tree

3 files changed

+48
-2
lines changed
Filter options
Expand file treeCollapse file tree

3 files changed

+48
-2
lines changed

‎src/Symfony/Component/HttpKernel/HttpClientKernel.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/HttpKernel/HttpClientKernel.php
+1-2Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ final class HttpClientKernel implements HttpKernelInterface
3535

3636
public function __construct(HttpClientInterface $client = null)
3737
{
38-
if (!class_exists(HttpClient::class)) {
38+
if (null === $client && !class_exists(HttpClient::class)) {
3939
throw new \LogicException(sprintf('You cannot use "%s" as the HttpClient component is not installed. Try running "composer require symfony/http-client".', __CLASS__));
4040
}
4141

@@ -53,7 +53,6 @@ public function handle(Request $request, $type = HttpKernelInterface::MASTER_REQ
5353
$response = $this->client->request($request->getMethod(), $request->getUri(), [
5454
'headers' => $headers,
5555
'body' => $body,
56-
'max_redirects' => 0,
5756
] + $request->attributes->get('http_client_options', []));
5857

5958
$response = new Response($response->getContent(!$catch), $response->getStatusCode(), $response->getHeaders(!$catch));
+46Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\HttpKernel\Tests;
13+
14+
use PHPUnit\Framework\TestCase;
15+
use Symfony\Component\HttpFoundation\Request;
16+
use Symfony\Component\HttpKernel\HttpClientKernel;
17+
use Symfony\Contracts\HttpClient\HttpClientInterface;
18+
use Symfony\Contracts\HttpClient\ResponseInterface;
19+
20+
class HttpClientKernelTest extends TestCase
21+
{
22+
public function testHandlePassesMaxRedirectsHttpClientOption()
23+
{
24+
$request = new Request();
25+
$request->attributes->set('http_client_options', ['max_redirects' => 50]);
26+
27+
$response = $this->getMockBuilder(ResponseInterface::class)->getMock();
28+
$response->expects($this->once())->method('getStatusCode')->willReturn(200);
29+
30+
$client = $this->getMockBuilder(HttpClientInterface::class)->getMock();
31+
$client
32+
->expects($this->once())
33+
->method('request')
34+
->willReturnCallback(function (string $method, string $uri, array $options) use ($request, $response) {
35+
$this->assertSame($request->getMethod(), $method);
36+
$this->assertSame($request->getUri(), $uri);
37+
$this->assertArrayHasKey('max_redirects', $options);
38+
$this->assertSame(50, $options['max_redirects']);
39+
40+
return $response;
41+
});
42+
43+
$kernel = new HttpClientKernel($client);
44+
$kernel->handle($request);
45+
}
46+
}

‎src/Symfony/Component/HttpKernel/composer.json

Copy file name to clipboardExpand all lines: src/Symfony/Component/HttpKernel/composer.json
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
"php": ">=7.1.3",
2020
"symfony/error-handler": "^4.4",
2121
"symfony/event-dispatcher": "^4.4",
22+
"symfony/http-client-contracts": "^1.1|^2",
2223
"symfony/http-foundation": "^4.4|^5.0",
2324
"symfony/polyfill-ctype": "^1.8",
2425
"symfony/polyfill-php73": "^1.9",

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.