httpClient = $httpClient; } /** * @throws InvalidUrlException */ public function validateUrl(string $url): void { // FIXME Guzzle is about to add support for this https://github.com/guzzle/guzzle/pull/2286 // Remove custom implementation when Guzzle's PR is merged $uri = new Uri($url); $originalHost = $uri->getHost(); $normalizedHost = idn_to_ascii($originalHost, IDNA_DEFAULT, INTL_IDNA_VARIANT_UTS46); if ($originalHost !== $normalizedHost) { $uri = $uri->withHost($normalizedHost); } try { $this->httpClient->request(self::METHOD_GET, (string) $uri, [ RequestOptions::ALLOW_REDIRECTS => ['max' => self::MAX_REDIRECTS], ]); } catch (GuzzleException $e) { throw InvalidUrlException::fromUrl($url, $e); } } }