Skip to content

Commit 996a11d

Browse files
[HttpClient] Don't throw InvalidArgumentException on bad Location header
1 parent b4a14bc commit 996a11d

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

HttpClient/Test/Fixtures/web/index.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,10 @@
5555
header('Location: http://foo.example.', true, 301);
5656
break;
5757

58+
case '/301/invalid':
59+
header('Location: //?foo=bar', true, 301);
60+
break;
61+
5862
case '/302':
5963
if (!isset($vars['HTTP_AUTHORIZATION'])) {
6064
header('Location: http://localhost:8057/', true, 302);

HttpClient/Test/HttpClientTestCase.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,20 @@ public function testRedirects()
259259
$this->assertSame($expected, $filteredHeaders);
260260
}
261261

262+
public function testInvalidRedirect()
263+
{
264+
$client = $this->getHttpClient(__FUNCTION__);
265+
$response = $client->request('GET', 'http://localhost:8057/301/invalid');
266+
267+
$this->assertSame(301, $response->getStatusCode());
268+
$this->assertSame(['//?foo=bar'], $response->getHeaders(false)['location']);
269+
$this->assertSame(0, $response->getInfo('redirect_count'));
270+
$this->assertNull($response->getInfo('redirect_url'));
271+
272+
$this->expectException(RedirectionExceptionInterface::class);
273+
$response->getHeaders();
274+
}
275+
262276
public function testRelativeRedirects()
263277
{
264278
$client = $this->getHttpClient(__FUNCTION__);

0 commit comments

Comments
 (0)