API / Minn\Http / Destination

Destination final readonly class

Minn\Http\Destination · public/minn/src/Minn/Http/Destination.php · 102 lines

Where Minn\Http lets a request go. Only http and https; when hosts are named, every hop must start with one of them (and with one of the client's own, when it is bound); and an address outside the public internet (loopback, private and shared ranges, link-local, cloud metadata, reserved) is refused unless its host is listed in $private. A name is resolved here and curl is pinned to the addresses that were checked, so DNS cannot answer one way to the check and another to the connection.

Constants and properties

privatereadonly array $private
privatereadonly array $hosts

Promoted from the constructor.

privatereadonly ?Closure $lookup

Promoted from the constructor.

privatereadonly array $within

Promoted from the constructor.

Public

new__construct(array $hosts = array ( ), array $private = array ( ), ?Closure $lookup = NULL, array $within = array ( ))#
$hostslist<string>URL prefixes every hop must start with; none means any public host
$privatelist<string>host names or addresses allowed to reach a private address
$lookup(Closure(string): list<string>)|nulla host's addresses; DNS when null
$withinlist<string>URL prefixes the client itself is bound to (an extension's needs.http); none means unbound
methodrefusal(string $url): ?string#

Why $url may not be requested, or null when nothing about the URL itself refuses it (a name is judged again once resolved).

methodpinned(Minn\Http\Outbound $request): Minn\Http\Outbound|Minn\Http\Exchange#

The request with curl pinned to the addresses its host resolves to, or the failed exchange when the name does not resolve or resolves somewhere private it was not allowed.

statichost(string $url): string#

A URL's host, lower-cased, without the brackets around an IPv6 address.

Internals 3

Private and protected methods: how the class does its work. Not a contract; they change whenever the code is tidied.

privatestartsWithOne(string $url, array $prefixes): bool#
$prefixeslist<string>
privateallowed(string $host, string $address): bool#
privatedns(string $host): array#

A name's IPv4 addresses, or its IPv6 ones when it has none.

@return list<string>