mirror of
https://github.com/lunarmodules/luasocket.git
synced 2024-12-26 04:28:20 +01:00
Modify http.lua to do a host lookup first, to determine the right
address family to use (previously tcp was the default).
This commit is contained in:
parent
6d5e40c324
commit
4785d9e6fc
14
src/http.lua
14
src/http.lua
@ -107,8 +107,16 @@ end
|
|||||||
local metat = { __index = {} }
|
local metat = { __index = {} }
|
||||||
|
|
||||||
function _M.open(host, port, create)
|
function _M.open(host, port, create)
|
||||||
-- create socket with user connect function, or with default
|
-- create socket with user connect function, or do a lookup to default to
|
||||||
local c = socket.try((create or socket.tcp)())
|
-- either tcp or tcp6 instead
|
||||||
|
if not create then
|
||||||
|
create = socket.tcp
|
||||||
|
local addrinfo, err = socket.dns.getaddrinfo(host)
|
||||||
|
if addrinfo and addrinfo[1] and addrinfo[1].family == "inet6" then
|
||||||
|
create = socket.tcp6
|
||||||
|
end
|
||||||
|
end
|
||||||
|
local c = socket.try(create())
|
||||||
local h = base.setmetatable({ c = c }, metat)
|
local h = base.setmetatable({ c = c }, metat)
|
||||||
-- create finalized try
|
-- create finalized try
|
||||||
h.try = socket.newtry(function() h:close() end)
|
h.try = socket.newtry(function() h:close() end)
|
||||||
@ -353,4 +361,4 @@ _M.request = socket.protect(function(reqt, body)
|
|||||||
else return trequest(reqt) end
|
else return trequest(reqt) end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
return _M
|
return _M
|
||||||
|
Loading…
Reference in New Issue
Block a user