Skip to content

Commit

Permalink
Simplify skipping DNS lookup when connecting to IP addresses
Browse files Browse the repository at this point in the history
  • Loading branch information
clue committed Apr 23, 2018
1 parent d395731 commit df02c39
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/DnsConnector.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ public function connect($uri)
$host = trim($parts['host'], '[]');
$connector = $this->connector;

// skip DNS lookup / URI manipulation if this URI already contains an IP
if (false !== filter_var($host, FILTER_VALIDATE_IP)) {
return $connector->connect($uri);
}

return $this
->resolveHostname($host)
->then(function ($ip) use ($connector, $host, $parts) {
Expand Down Expand Up @@ -86,10 +91,6 @@ public function connect($uri)

private function resolveHostname($host)
{
if (false !== filter_var($host, FILTER_VALIDATE_IP)) {
return Promise\resolve($host);
}

$promise = $this->resolver->resolve($host);

return new Promise\Promise(
Expand Down

0 comments on commit df02c39

Please sign in to comment.