Skip to content

Commit

Permalink
Merge pull request #28 from Hevienz/master
Browse files Browse the repository at this point in the history
Remove resolve function
  • Loading branch information
wendal committed May 20, 2014
2 parents 869907f + 4367cbf commit e213398
Showing 1 changed file with 1 addition and 46 deletions.
47 changes: 1 addition & 46 deletions lib/resty/http.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand Down

0 comments on commit e213398

Please sign in to comment.