[HttpClient] fix requests to hosts that idn_to_ascii() cannot handle

This commit is contained in:
Nicolas Grekas 2020-03-11 09:13:51 +01:00
parent 14b825b24f
commit 4b45685306
2 changed files with 18 additions and 4 deletions

View File

@ -441,10 +441,7 @@ trait HttpClientTrait
throw new InvalidArgumentException(sprintf('Unsupported IDN "%s", try enabling the "intl" PHP extension or running "composer require symfony/polyfill-intl-idn".', $host));
}
if (false === $host = \defined('INTL_IDNA_VARIANT_UTS46') ? idn_to_ascii($host, IDNA_DEFAULT, INTL_IDNA_VARIANT_UTS46) : strtolower($host)) {
throw new InvalidArgumentException(sprintf('Unsupported host in "%s".', $url));
}
$host = \defined('INTL_IDNA_VARIANT_UTS46') ? idn_to_ascii($host, IDNA_DEFAULT, INTL_IDNA_VARIANT_UTS46) ?: strtolower($host) : strtolower($host);
$host .= $port ? ':'.$port : '';
}

View File

@ -703,6 +703,23 @@ abstract class HttpClientTestCase extends TestCase
$client->request('GET', 'http://symfony.com:8057/', ['timeout' => 1]);
}
public function testIdnResolve()
{
$client = $this->getHttpClient(__FUNCTION__);
$response = $client->request('GET', 'http://0-------------------------------------------------------------0.com:8057/', [
'resolve' => ['0-------------------------------------------------------------0.com' => '127.0.0.1'],
]);
$this->assertSame(200, $response->getStatusCode());
$response = $client->request('GET', 'http://Bücher.example:8057/', [
'resolve' => ['xn--bcher-kva.example' => '127.0.0.1'],
]);
$this->assertSame(200, $response->getStatusCode());
}
public function testNotATimeout()
{
$client = $this->getHttpClient(__FUNCTION__);