Skip to content

Commit f1b0825

Browse files
committed
code review: fixed several review comments.
1 parent 185f106 commit f1b0825

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

lib/ngx/resolver.lua

+11-8
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ local base = require "resty.core.base"
22
local get_request = base.get_request
33
local ffi = require "ffi"
44
local C = ffi.C
5-
local ffi_new = ffi.new
65
local ffi_str = ffi.string
76
local ffi_gc = ffi.gc
87
local FFI_OK = base.FFI_OK
@@ -47,18 +46,22 @@ local mt = {
4746
local Ctx = ffi.metatype("ngx_http_lua_resolver_ctx_t", mt)
4847

4948
function _M.resolve(hostname, ipv4, ipv6)
50-
assert(type(hostname) == "string", "hostname must be string")
51-
assert(ipv4 == nil or type(ipv4) == "boolean", "ipv4 must be boolean or nil")
52-
assert(ipv6 == nil or type(ipv6) == "boolean", "ipv6 must be boolean or nil")
53-
5449
local buf = get_string_buf(BUF_SIZE)
5550
local buf_size = get_size_ptr()
5651
buf_size[0] = BUF_SIZE
5752

58-
local ctx = Ctx({get_request(), buf, buf_size})
53+
local ctx = Ctx()
54+
ctx.request = get_request()
55+
ctx.buf = buf
56+
ctx.buf_size = buf_size
57+
58+
if ipv4 == nil or ipv4 then
59+
ctx.ipv4 = 1
60+
end
5961

60-
ctx.ipv4 = ipv4 == nil and 1 or ipv4
61-
ctx.ipv6 = ipv6 == nil and 0 or ipv6
62+
if ipv6 then
63+
ctx.ipv6 = 1
64+
end
6265

6366
local rc = C.ngx_http_lua_ffi_resolve(ctx, hostname)
6467

0 commit comments

Comments
 (0)