From 4367cbf1a47045b731f8888be48a885d7824d092 Mon Sep 17 00:00:00 2001 From: Hevienz Date: Tue, 20 May 2014 10:00:59 +0800 Subject: [PATCH] Remove resolve function --- lib/resty/http.lua | 47 +--------------------------------------------- 1 file changed, 1 insertion(+), 46 deletions(-) diff --git a/lib/resty/http.lua b/lib/resty/http.lua index 7f819f7..9e1edcf 100644 --- a/lib/resty/http.lua +++ b/lib/resty/http.lua @@ -249,42 +249,6 @@ function new(self) return setmetatable({}, mt) end -local resolver = require "resty.dns.resolver" -local function resolve(host) - local r, err = resolver:new{ - nameservers = {"8.8.8.8", {"8.8.4.4", 53} }, - retrans = 5, -- 5 retransmissions on receive timeout - timeout = 2000, -- 2 sec - } - - if not r then - ngx.say("failed to instantiate the resolver: ", err) - return - end - - local answers, err = r:query(host) - if not answers then - ngx.say("failed to query the DNS server: ", err) - return - end - - if answers.errcode then - ngx.say("server returned error code: ", answers.errcode, - ": ", answers.errstr) - end - - for i, ans in ipairs(answers) do - --ngx.say(ans.name, " ", ans.address or ans.cname, - -- " type:", ans.type, " class:", ans.class, - -- " ttl:", ans.ttl) - if ans.address then - return ans.address - end - end - - return nil -end - function request(self, reqt) local code, headers, status, body, bytes, ok, err @@ -297,17 +261,8 @@ function request(self, reqt) sock:settimeout(nreqt.timeout) - -- determine nreqt.host is a domain name or a ip address - local is_ip=string.match(nreqt.host,"%d+%.%d+%.%d+%.%d+") - local address=nil - if is_ip then - address=nreqt.host - else - address=resolve(nreqt.host) - end - -- connect - ok, err = sock:connect(address, nreqt.port) + ok, err = sock:connect(nreqt.host, nreqt.port) if err then return nil, "sock connected failed " .. err end