From df02c393c6fac9131c9a2c4010b900d4a512bb29 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20L=C3=BCck?= Date: Mon, 23 Apr 2018 11:40:15 +0200 Subject: [PATCH] Simplify skipping DNS lookup when connecting to IP addresses --- src/DnsConnector.php | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/DnsConnector.php b/src/DnsConnector.php index 90170e54..0dfd6585 100644 --- a/src/DnsConnector.php +++ b/src/DnsConnector.php @@ -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) { @@ -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(