Skip to content

Commit 1a12e12

Browse files
minor symfony#58949 [HttpClient] resolve IPv6 addresses with amphp/http-client 5 (xabbuh)
This PR was merged into the 7.2 branch. Discussion ---------- [HttpClient] resolve IPv6 addresses with amphp/http-client 5 | Q | A | ------------- | --- | Branch? | 7.2 | Bug fix? | yes | New feature? | no | Deprecations? | no | Issues | | License | MIT following the changes from symfony#58915 Commits ------- 3a732af resolve IPv6 addresses with amphp/http-client 5
2 parents 54cd626 + 3a732af commit 1a12e12

File tree

1 file changed

+18
-4
lines changed

1 file changed

+18
-4
lines changed

src/Symfony/Component/HttpClient/Internal/AmpResolverV5.php

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,19 +32,33 @@ public function __construct(
3232

3333
public function resolve(string $name, ?int $typeRestriction = null, ?Cancellation $cancellation = null): array
3434
{
35-
if (!isset($this->dnsMap[$name]) || !\in_array($typeRestriction, [DnsRecord::A, null], true)) {
35+
$recordType = DnsRecord::A;
36+
$ip = $this->dnsMap[$name] ?? null;
37+
38+
if (null !== $ip && str_contains($ip, ':')) {
39+
$recordType = DnsRecord::AAAA;
40+
}
41+
42+
if (null === $ip || $recordType !== ($typeRestriction ?? $recordType)) {
3643
return Dns\resolve($name, $typeRestriction, $cancellation);
3744
}
3845

39-
return [new DnsRecord($this->dnsMap[$name], DnsRecord::A, null)];
46+
return [new DnsRecord($ip, $recordType, null)];
4047
}
4148

4249
public function query(string $name, int $type, ?Cancellation $cancellation = null): array
4350
{
44-
if (!isset($this->dnsMap[$name]) || DnsRecord::A !== $type) {
51+
$recordType = DnsRecord::A;
52+
$ip = $this->dnsMap[$name] ?? null;
53+
54+
if (null !== $ip && str_contains($ip, ':')) {
55+
$recordType = DnsRecord::AAAA;
56+
}
57+
58+
if (null !== $ip || $recordType !== $type) {
4559
return Dns\resolve($name, $type, $cancellation);
4660
}
4761

48-
return [new DnsRecord($this->dnsMap[$name], DnsRecord::A, null)];
62+
return [new DnsRecord($ip, $recordType, null)];
4963
}
5064
}

0 commit comments

Comments
 (0)