[HttpClient] fix requests to hosts that idn_to_ascii() cannot handle
This commit is contained in:
parent
14b825b24f
commit
4b45685306
|
@ -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 : '';
|
||||
}
|
||||
|
||||
|
|
|
@ -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__);
|
||||
|
|
Reference in New Issue